包com.google.gson.internal.bind.util在模块com.google.gson中声明,但模块不会导出它

ulydmbyx  于 11个月前  发布在  Go
关注(0)|答案(2)|浏览(144)

我在编译OpenAPI生成器生成的代码时得到了这个错误消息:

package com.google.gson.internal.bind.util is declared in module com.google.gson, which does not export it

字符串
在我的build.gradle中,我使用了这个依赖项:

implementation 'com.google.code.gson:gson:2.10.1'


在我的网站module-info.java上,我包括:

requires com.google.gson;

zd287kbt

zd287kbt1#

在build.gradle中包含“--add-exports $MOTORY/$PACKAGE=$阅读_MOTORY”:

compileJava {
doFirst {
    options.compilerArgs = [
            '--module-path', classpath.asPath,                
            '--add-exports', 'com.google.gson/com.google.gson.internal.bind.util=MyModule' // resolves "package com.google.gson.internal.bind.util is declared in module com.google.gson, which does not export it" 
    ]
    classpath = files()                                            
}

字符串
}

iszxjhcz

iszxjhcz2#

虽然添加编译器选项以允许访问此包解决了错误,但问题是为什么首先依赖内部Gson包,以及是否有官方替代方案。
根据包名,听起来你在使用Gson的内部ISO8601Utils类。更好的替代方案是使用java.time packagejava.time.format.DateTimeFormatter class中的类来格式化和解析日期。

相关问题