Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gradle 4.1 task

2.9k views Asked by At

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

There are 1 answers

2
Taivaan On

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']
    }
}