问题描述
我有一个可以通过 eclipse(ECJ)构建良好的项目,但是 Oracle javac 无法构建它(某些原因,如链接中的)。
我想从eclipse转到Gradle构建,以便Jenkins可以运行Gradle脚本。但是Gradle总是使用javac进行编译。我使用插件 eclipse,eclipse-wtp或库,对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']
}
}
问题:我不知道这样的方式(没有文档,有些的方式,但过期与旧的gradle或不正确的)gradle 4.1使用Eclipse编译器(ECJ)运行任务来编译我期望的类。
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.
推荐答案
将其添加到gradle构建中脚本对我有用:
Adding this to the gradle build script worked for me:
configurations {
ecj
}
dependencies {
ecj 'org.eclipse.jdt.core.compiler:ecj:4.6.1'
}
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!