Gradle:如何通过运行Gradle 4.1任务通过eclipse ECJ(JDT核心)编译Java [英] Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gradle 4.1 task

查看:176
本文介绍了Gradle:如何通过运行Gradle 4.1任务通过eclipse ECJ(JDT核心)编译Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以通过 eclipse(ECJ)构建良好的项目,但是 Oracle javac 无法构建它(某些原因,如链接中的ecj和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.


注意:我由javac构建时出现此错误:与javac不兼容的类型。我想通过ECJ通过任务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.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆