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

ぐ巨炮叔叔 提交于 2019-12-13 17:50:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!