Java 如何制作GitHub';在IntelliJ+;格拉德尔
我使用GitHub的库进行Android开发,现在我想在后端也尝试一下 在安卓系统中,使用该库所需的一切是:Java 如何制作GitHub';在IntelliJ+;格拉德尔,java,intellij-idea,gradle,build.gradle,immutables-library,Java,Intellij Idea,Gradle,Build.gradle,Immutables Library,我使用GitHub的库进行Android开发,现在我想在后端也尝试一下 在安卓系统中,使用该库所需的一切是: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // immutable entities generation provided "org.immutables:value:2.5.5" // for annotations provided "org.immutable
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// immutable entities generation
provided "org.immutables:value:2.5.5" // for annotations
provided "org.immutables:builder:2.5.5" // for annotations
provided "org.immutables:gson:2.5.5" // for annotations
... other dependencies
}
当我试图将上述依赖项复制到我的Java项目的build.gradle
中时,我得到以下错误:
Error:(24, 0) Gradle DSL method not found: 'provided()'
我试图用compileOnly
和compile
替换提供的,但随后用@值注释的接口的实现不会生成不可变的
我如何让它工作?找到了答案。分享,以防将来对任何人(或我自己)都有帮助
首先,我必须如前所述在IntelliJ中启用注释处理(尽管该选项现在位于Settings>Build,Execution,Deployment>Compiler>annotation Processors
)
之后,以下代码开始实际生成实现:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// immutable entities generation
compile "org.immutables:value:2.5.5" // for annotations
compile "org.immutables:builder:2.5.5" // for annotations
compile "org.immutables:gson:2.5.5" // for annotations
... other dependencies
}
但是,我仍然无法将实现自动导入到源文件中
为了允许发现生成的类,我必须右键单击main
包中的generated
文件夹,然后将目录标记为>generated Sources Root
,我不能添加注释(rep太低),但对于未来的读者,我想扩展
在我的例子中(版本5.2.1中的gradle包装器),以下代码自动神奇地发现生成的源代码:
dependencies {
def immutablesVersion = "2.8.2"
annotationProcessor "org.immutables:value:$immutablesVersion" // <--- this is important
compileOnly "org.immutables:value:$immutablesVersion"
}
依赖项{
def ImmutableVersion=“2.8.2”
annotationProcessor“org.immutables:值:$immutableVersion”//由于这是对现有答案的扩展,提供了回答问题的其他信息,因此将其作为答案发布是完全合法的。即使您拥有评论权限,答案仍然是合理的。正如一般提示一样,如果您直接引用另一个答案,您可以像我一样通过编辑您的帖子链接到它。I要知道,如果只有一个答案,这似乎并不重要,但将来还会有更多答案,所以拥有它很好:)