How can I use custom configurations with the Eclipse plugin?


(Christopher Molozian) #1

I’ve followed some online information on how to setup Project Lombok (http://projectlombok.org/) with Gradle. My build script looks like this:

apply plugin: "java"
apply plugin: "eclipse"
  [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
  repositories {
    mavenCentral()
}
  configurations {
    compileOnly
    testCompileOnly { extendsFrom compileOnly }
}
  sourceSets {
    main {
        compileClasspath += configurations.compileOnly
    }
    test {
        compileClasspath += configurations.compileOnly + configurations.testCompileOnly
    }
}
  dependencies {
    compileOnly group: "org.projectlombok", name: "lombok", version: "0.10.1"
    // etc...
}

This works very well except when I generate an eclipse project (using “gradle eclipse”), the lombok jar isn’t added to eclipse’s .classpath config file.

How do I reconfigure the gradle eclipse plugin to add the “compileOnly” configuration to the eclipse .classpath file generation?


(Gary Hale) #2

By default, the eclipse plugin uses the testRuntime configuration to generate classpath entries. Since you are defining your dependency in a custom configuration (compileOnly) the eclipse plugin does not see it. To add it to the configurations it uses to generate classpath entries, do something like the following:

eclipseClasspath {
 plusConfigurations += [ configurations.compileOnly ]
}