[英]Integrating annotation processors with Gradle
I need to write some annotation processors. 我需要编写一些注释处理器。 I found this blog post which mentions how that can be done in a general setting and with Eclipse.
我发现这篇博客文章提到了如何在一般环境和Eclipse中完成。
However I am using IntelliJ IDEA and Gradle, and woud like it if there were a better (as in, less tedious) approach to do it. 但是我使用的是IntelliJ IDEA和Gradle,并且如果有更好的(如同,不那么繁琐)的方法,那么它就像它一样。 What I am looking for:
我在找什么:
My git and Gradle skills are beginner level. 我的git和Gradle技能是初学者级别的。 I would appreciate any help with this task.
我很感激任何帮助这项任务。 Thank you.
谢谢。
Yes, it is possible to move processor to separated module and use it from another module (see querydslapt
below). 是的,可以将处理器移动到分离的模块并从另一个模块使用它(参见下面的
querydslapt
)。
I will recomend you to implement your own AbstractProcessor 我建议你实现自己的AbstractProcessor
and use it like that: 并使用它:
dependencies {
....
// put dependency to your module with processor inside
querydslapt "com.mysema.querydsl:querydsl-apt:$querydslVersion"
}
task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
source = sourceSets.main.java // input source set
classpath = configurations.compile + configurations.querydslapt // add processor module to classpath
// specify javac arguments
options.compilerArgs = [
"-proc:only",
"-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor" // your processor here
]
// specify output of generated code
destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}
Another solution (in my opinion cleaner) could be to have two subprojects and then simply make the one that contains annotation processors a dependency of the main one. 另一个解决方案(在我看来更干净)可能是有两个子项目 ,然后简单地使包含注释处理器的子项目与主要项目相关。 So given two directories with your subprojects:
core
and annotation-processors
in the root of your project, you would need to also have a settings.gradle
file with the following: 因此,给定子项目的两个目录:项目根目录中的
core
和annotation-processors
,您还需要具有以下settings.gradle
文件:
include 'core'
include 'annotation-processors'
And then in the gradle file for the core project: 然后在核心项目的gradle文件中:
dependencies {
compile project(':annotation-processors')
}
That should do it and you won't have to deal with custom compile tasks and their classpaths. 应该这样做,你不必处理自定义编译任务及其类路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.