u1234
(tulsoba)
May 13, 2013, 12:46pm
1
I build a gradle project with:
gradle clean publishToMavenLocal
In the build.gradle file I need to exclude all transitive dependencies for ‘commons-jxpath’
dependencies {
compile("commons-jxpath:commons-jxpath:1.2") {
exclude group: '*'
}
But in the generated pom nothing is set to exclude:
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
I would expect:
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.2</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
Do I specify the exclusion for the dependency incorrectly or is it not supported in the maven-publish plugin (worked with the maven plugin)
daz
May 14, 2013, 10:22pm
2
Excludes are not (yet) supported by the maven-publish plugin. You’ll need to use ‘pom.withXml’.
u1234
(tulsoba)
May 15, 2013, 7:30am
3
Is there a feature issue for this eg. GRADLE-XYZ/Fix version?
dlethin
(Doug Lethin)
November 1, 2013, 6:53pm
4
Any updates on this? Is there a JIRA ticket for this we can watch and vote for? Thanks.
daz
November 1, 2013, 10:22pm
5
I’ve raised GRADLE-2945 to track this issue. If you really need a solution in the short term then a pull request is your best bet.
luke_daley
(Luke Daley)
November 2, 2013, 10:45am
6
There’s definitely already an issue for this. Might be worth finding it and closing it as a duplicate of the one you just raised Daz.
daz
November 3, 2013, 5:28am
7
I couldn’t find an existing bug and still can’t. There are a few bugs around how excludes are generated with the old publishing stuff, but nothing that I can find about how excludes are completely missing from the new publishing plugins.
quidryan
(Justin Ryan)
November 23, 2013, 4:17am
8
Are there any examples of how pom.withXml would be used?
All I can find is: http://www.gradle.org/docs/current/userguide/userguide_single.html#N16D4F . ‘asNode()’ returns a ‘groovy.util.Node’ just like ‘groovy.util.XmlParser#parseText’ does. You can find some ‘XmlParser’ examples here: http://groovy.codehaus.org/Updating+XML+with+XmlParser
atschabu
(atschabu)
January 29, 2014, 10:50am
10
that should do the trick:
project.publishing {
publications {
mavenJar(MavenPublication) {
from(project.components.java)
project.configurations[JavaPlugin.RUNTIME_CONFIGURATION_NAME].allDependencies.findAll {
it instanceof ModuleDependency && !it.excludeRules.isEmpty()
}.each { ModuleDependency dep ->
pom.withXml {
def xmlDep = asNode().dependencies.dependency.find {
it.groupId[0].text() == dep.group && it.artifactId[0].text() == dep.name
}
def xmlExclusions = xmlDep.exclusions[0]
if (!xmlExclusions) xmlExclusions = xmlDep.appendNode(‘exclusions’)
dep.excludeRules.each { ExcludeRule rule ->
def xmlExclusion = xmlExclusions.appendNode(‘exclusion’)
xmlExclusion.appendNode(‘groupId’, rule.group)
xmlExclusion.appendNode(‘artifactId’, rule.module)
}
}
}
}
}
}