How can I use the JDT compiler with Gradle 1.0-m9?

I prefer the Eclipse JDT compiler for javac and with gradle -1.0-m7 and older it works like this:

compileJava {
    options.compiler = "org.eclipse.jdt.core.JDTCompilerAdapter"
    options.encoding = 'utf-8'
    options.define(compilerArgs: ["-warn:+${warnings.join(',')}"])
    doFirst {
        ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
        configurations.ecj.each { File f ->
            antClassLoader.addURL(f.toURI().toURL())
        }
    }
}

      

But with gradle -1.0-milestone-9 I got the following warning ( but still works ):

The property has CompileOptions.compiler

been deprecated and will be removed in the next version of Gradle. To use an alternate compiler, set ' CompileOptions.fork

' to 'true' and ' CompileOptions.forkOptions.executable

' to the path of the compiler executable.

It says that CompileOptions.forkOptions.executable

is a new way to use an alternative compiler. However, the JDT compiler does not have an executable and is intended to be used with ant. (I'm right?)

So, I would like to know how to use the JDT compiler correctly with gradle 1.0-m9?

Thank.


Updated on March 27th,

I found a way to run the JDT compiler 'executable', in fact by running the java executable

compileJava.doFirst {
    def ecjJar = configurations.ecj.singleFile

    options.fork = true
    options.fork executable: 'java', jvmArgs: [ '-cp', ecjJar.path, 'org.eclipse.jdt.internal.compiler.batch.Main' ]
    options.define compilerArgs: [
        '-encoding', 'utf-8',
        '-source', sourceCompatibility,
        '-target', targetCompatibility,
        "-warn:+${warnings.join(',')}"
    ]
}

      

This works, but it looks a little strange:

  • compiler executable - 'java'
  • I have to redirect all compilation options to the forked executable like command line options

I would like to find a groovy, at least ant way to do this.


Updated March 31st,

After digging through the gradle codes, I found that the options.compiler

only way to use an alternative compiler with ant (in gradle) is that it AntJavaCompiler

will create a new AntBuilder instance before compiling, so the ant property build.compiler

has no effect here.

So, I would apply the above "java executable" solution before finding a better way.

And I posted this solution as a gradle plugin on GitHub , hope it helps.

+3


source to share


1 answer


It looks like it will only bind to external executable compilers. Maybe you can just override the whole compileJava task?

task compileJava(overwrite: true) << {
    ant. ... (run your ant JDT compiler)
}

      



I'm a little sure if there will be any side effects from this.

0


source







All Articles