On 11/10/2010, at 8:02 PM, David Resnick wrote:

> Hi,
> 
> I'm new to using Gradle, and have a question about configuring the
> compileJava task.
> 
> I've set the compiler to use with
> compileJava.options.define(compiler: 
> "org.eclipse.jdt.core.JDTCompilerAdapter")
> 
> but I need to include the ecj.jar in the compiler classpath.
> 
> I created a special configuration but I can't seem to make it
> available for finding the compiler in the compileJava task.
> 
> configurations { jdt {} }
> dependencies {
>       jdt "org.eclipse.jdt:ecj:3.5"
> }
> compileJava.options.define(bootClasspath: configurations.jdt.files)
> 
> It looks like the ant javac property I need to set is
> compilerClasspath, which doesn't seem to be settable in the
> CompileJava Groovy class (it isn't listed in the Groovy
> documentation).
> 
> Is there anyway to do this apart from putting the ecj jar file inside
> my gradle dist lib folder?

Sort of.  You can do the same sort of thing by instead injecting the jars into 
the Ant classloader from the build script. Here's an example:

configurations {
    jdt
}

dependencies {
    jdt "org.eclipse.jdt:ecj:3.5"
}

compileJava {
    options.compiler = "org.eclipse.jdt.core.JDTCompilerAdapter"
    doFirst {
        ClassLoader antClassLoader = 
org.apache.tools.ant.Project.class.classLoader
        configurations.jdt.each { File f ->
            antClassLoader.addURL(f.toURI().toURL())
        }
    }
}


I'm curious why you want to use the eclipse compiler, if you don't mind me 
asking?


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to