mis*_*tor 27 java annotations intellij-idea gradle
我需要编写一些注释处理器.我发现这篇博客文章提到了如何在一般环境和Eclipse中完成.
但是我使用的是IntelliJ IDEA和Gradle,并且如果有更好的(如同,不那么繁琐)的方法,那么它就像它一样.我在找什么:
我的git和Gradle技能是初学者级别的.我很感激任何帮助这项任务.谢谢.
是的,可以将处理器移动到分离的模块并从另一个模块使用它(见querydslapt下文).
我建议你实现自己的AbstractProcessor
并使用它:
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()
}
Run Code Online (Sandbox Code Playgroud)
你可以在这里找到完整的例子
另一个解决方案(在我看来更干净)可能是有两个子项目,然后简单地使包含注释处理器的子项目与主要项目相关.因此,考虑两个目录与您的子项目:core和annotation-processors你的项目的根,你还需要有一个settings.gradle具有下列文件:
include 'core'
include 'annotation-processors'
Run Code Online (Sandbox Code Playgroud)
然后在核心项目的gradle文件中:
dependencies {
compile project(':annotation-processors')
}
Run Code Online (Sandbox Code Playgroud)
应该这样做,你不必处理自定义编译任务及其类路径.
| 归档时间: |
|
| 查看次数: |
16951 次 |
| 最近记录: |