【发布时间】:2018-09-02 08:54:52
【问题描述】:
我正在从 maven 切换到 gradle。
这是我以前在 pom.xml 中的内容
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
</execution>
<execution>
<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<sourceDirectory>./test</sourceDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>rockpalm.it</groupId>
<artifactId>ic2-annotation-processor</artifactId>
<version>1.2.1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
我的 build.gradle 看起来像:
plugins {
id "net.ltgt.apt" version "0.15"
id 'net.ltgt.apt-eclipse' version '0.15'
}
dependencies {
annotationProcessor "rockpalm.it:ic2-annotation-processor:1.2.1-SNAPSHOT"
}
ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}
eclipse {
jdt.file.withProperties {
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
}
}
tasks.eclipseJdt {
doFirst {
def aptPrefs = file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
aptPrefs.parentFile.mkdirs()
aptPrefs.text = """\
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
org.eclipse.jdt.apt.reconcileEnabled=true
""".stripIndent()
file('.factorypath').withWriter {
new groovy.xml.MarkupBuilder(it).'factorypath' {
project.configurations.annotationProcessor.each { dep->
factorypathentry(
kind:'EXTJAR',
id:dep.absolutePath,
enabled:true,
runInBatchMode:false
)
}
}
}
}
}
但是当我使用 Gradle > Refresh gradle 项目时,它没有使用我的注释处理器配置 eclipse 的 .factorypath,它启用它但没有在处理器列表上设置实际处理器。
当我运行 gradle build 时,我实际上可以在 build/generated/source/apt/main/...my packages/classes 中看到我生成的代码,但由于它在 eclipse 中没有启用,所以我在 .apt_generated 文件夹中没有任何内容。
编辑
我得到了 gradle 以使用 build.gradle 的 tasks.eclipseJdt 部分正确构建工厂路径,但 eclipse 似乎仍然没有在 .apt_generated 构建任何东西。如何调试 eclipse gradle build 以查看发生了什么?
感谢任何帮助,谢谢
【问题讨论】:
-
我也有同样的问题。执行
gradle eclipse后——在eclipse中激活“注解处理”,“工厂路径”也设置正确。 Eclipse 不生成任何东西。 gradle build 正在控制台上运行。你找到工作了吗?
标签: gradle annotation-processing