问题
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']
}
}
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.
Note : This error when I built by javac: incompatible type with javac . I want to run well by task gradle with ECJ.
回答1:
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']
}
}
来源:https://stackoverflow.com/questions/46196120/gradle-how-to-compile-java-by-eclipse-ecj-jdt-core-by-running-gradle-4-1-task