Is it now possible to use the Intellij javac2 compiler in Gradle? This used to be possible, then it wasn't... Milestone 9 switched to Gradle's compiler


(Douglas Bullard) #1

I use Intellij IDEA’s Form Designer for my Swing UIs, and they provide a special compiler for that. I had it working in Ant, and reading some old posts it used to be possible to do this with Gradle, but it broke a while back.

I wanted to know if Milestone 9 made it possible again, since in the release notes it says they switched to a Gradle compiler (although you can still use the Ant javac).

There is a workaround for this (you can have Intellij generate Java code for the UI), but it’s ugly. I’d like to be able to tell Gradle which class to use for javac.

Is that possible, or planned?

Thanks,

Douglas Bullard


(Peter Niederwieser) #2

This should do the job:

compileJava {
    options.fork = true
    options.forkOptions.executable = "/path/to/compiler/executable"
}

The only drawback is that each ‘Compile’ task that has ‘executable’ set will have to spawn its own compiler (process). This can slow down the build, in particular for builds with many small projects.


(Douglas Bullard) #3

I don’t think that will work, as the Intellij javac replacement is in a jar file, and not an executable.

In my Ant builds, I’d do compilation like this:

<property name="javac2.home" value="${idea.home}/lib"/>
     <path id="javac2.classpath">
       <pathelement location="${javac2.home}/javac2.jar"/>
       <pathelement location="${javac2.home}/jdom.jar"/>
       <pathelement location="${javac2.home}/asm.jar"/>
       <pathelement location="${javac2.home}/asm-commons.jar"/>
       <pathelement location="${javac2.home}/jgoodies-forms.jar"/>
     </path>
     <target name="compile">
        <taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="${javac2.classpath}"/>
        <javac2 srcdir="${srcdir}" classpathref="${classpathRef}" destdir="${compile.out.dir}" debug="${compile.debug}" debugLevel="${compile.debugLevel}" deprecation="${compile.deprecation}" includeAntRuntime="@{includeAnt}" excludes="@{excludes}" optimize="${compile.optimize}" source="@{source}" target="@{target}"/>
       </target>

(Peter Niederwieser) #4

Looks like it is just an Ant task after all. You can use any Ant task from Gradle. For more information, consult the Ant chapter in the Gradle user guide.


(Douglas Bullard) #5

The point was that I was trying to use this as an alternate compiler in the Gradle lifecycle, but it doesn’t look like that’s possible

I guess I can run this via Ant in Gradle in a compile.doFirst section and see if Gradle’s compiler overwrites it (or if it does, put it into a doLast section).

Thanks.