Search code examples
eclipsegradlebuildgradle-eclipse

Gradle + Eclipse: How to not export JARs that are dependencies of a dependency?


In my build.gradle file I have the following:

...
dependencies {
  ...
  testCompile (group: 'org.uncommons', name: 'reportng', version: '1.1.2') { exclude group: 'org.testng', module: 'testng' }
  ...
}
...

reportng needs velocity-1.4.jar and velocity-dep-1.4.jar, and actually the above testCompile dependency causes these 2 JARs to be fetched and to be placed into the Eclipse's .classpath file, as "exported" (that is, their checkboxes in the "Order and Export" tab of Eclipse's "Java Build Path" dialog are checked).

The fact that these 2 JARs get set as exported is a problem. I need them to still be fetched but not to be exported.

From the Gradle doc I understand that this is done by using noExportConfigurations as per their example:

apply plugin: 'java'
apply plugin: 'eclipse'

configurations {
  provided
  someBoringConfig
}

eclipse {

  classpath {

    //if you don't want some classpath entries 'exported' in Eclipse
    noExportConfigurations += configurations.provided
  }
}

My problem is that I don't have a configurations {} section, and while I can certainly add one, I don't know what to put in it in order to exclude from export not the whole reportng but just two of the JARs that come with it.


Solution

  • You'll probably want something like:

    configurations {
        noExport
    }
    dependencies {
        // replace with correct values
        noExport "foo:velocity:1.4" 
        noExport "foo:velocity-dep:1.4"
    }
    eclipse {
        classpath {
            noExportConfigurations += configurations.noExport
        }
    }
    

    PS: Please don't double-post here and on http://forums.gradle.org.