Gradle:如何通过运行 Gradle 4.1 任务通过 Eclipse ECJ(JDT 核心)编译 Java [英] Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gradle 4.1 task
问题描述
我有一个可以通过 eclipse (ECJ) 很好地构建的项目,但是 Oracle javac 无法构建它(某些原因如链接:ecj 和 javac 的区别).我想从 eclipse 移动到由 Gradle 构建,以便 Jenkins 可以运行 Gradle 脚本.但是 Gradle 总是使用 javac 来编译.我使用了插件 'eclipse, eclipse-wtp' 或 library,jdt 对配置 gradle 的依赖,像那样使用 ECJ,但它仍然不使用 ECJ 进行编译:
I have a project that can be build well by eclipse (ECJ) But Oracle javac can't build it (some reasons like in link: the different of ecj and javac). I would like moving from eclipse to build by Gradle, in order to Jenkins can run Gradle script. But Gradle always use javac to compile. I used the plugins 'eclipse, eclipse-wtp' or library, dependency of jdt to config gradle use ECJ like that but it still don't use ECJ to compile:
compileJava{
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath','_mylibary_jdt_jar']
}
}
问题:我不知道使用 Eclipse Compiler (ECJ) 运行 gradle 4.1 任务以编译我期望的类的方式(没有文档,有些方式但已过期或不正确).
The problem: I don't know the way (no document, some ways but expired with old gradle or incorrect) gradle 4.1 run task with Eclipse Compiler (ECJ) to compile the classes I expected.
注意:当我用 javac 构建时出现这个错误:与 javac 不兼容的类型.我想通过 ECJ 的 task gradle 运行良好.
Note : This error when I built by javac: incompatible type with javac . I want to run well by task gradle with ECJ.
推荐答案
将此添加到 gradle 构建脚本对我有用:
Adding this to the gradle build script worked for me:
configurations {
ecj
}
dependencies {
ecj 'org.eclipse.jdt:ecj:3.25.0'
}
compileJava {
options.fork = true
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath', project.configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', '-nowarn']
}
}
这篇关于Gradle:如何通过运行 Gradle 4.1 任务通过 Eclipse ECJ(JDT 核心)编译 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!