Reputation: 1634
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.
Upvotes: 1
Views: 1579
Reputation: 34038
Apparently, in the year and a half that has gone by since Peter's answer, noExportConfigurations is deprecated and slated to be removed in Gradle 3.0. What's more, none of the solutions in the linked Gradle forum thread allow me to remove a dependency imported from a folder, like war/WEB-INF/lib, for instance.
So after much research, I stumbled upon an example here at the end of this build.gradle file in GitHub, which reorders entries in the classpath:
withXml { xml ->
def node = xml.asNode()
node.remove( node.find { it.@path == 'org.eclipse.jst.j2ee.internal.web.container' } )
node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
}
I modified the example so that it simply removes a JAR file using the regex capabilities of the Groovy Node. Note that the xml ->
part is not needed, and that this entry is a child of the file closure:
withXml {
def node = it.asNode()
node.remove( node.find { it.@path ==~ /.*velocity-1\.4\.jar/ } )
node.remove( node.find { it.@path ==~ /.*velocity-dep-1\.4\.jar/ } )
}
Upvotes: 1
Reputation: 123910
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.
Upvotes: 1