Maven-publish plugin does not add excludes to generated pom


(tulsoba) #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)


Plugin-publish plugin does not include transitive dependency rules in Pom
Maven-publish: Excluding transitive dependencies from a subproject in a multi-project build
#2

Excludes are not (yet) supported by the maven-publish plugin. You’ll need to use ‘pom.withXml’.


(tulsoba) #3

Is there a feature issue for this eg. GRADLE-XYZ/Fix version?


(Doug Lethin) #4

Any updates on this? Is there a JIRA ticket for this we can watch and vote for? Thanks.


#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) #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.


#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.


(Justin Ryan) #8

Are there any examples of how pom.withXml would be used?


(Peter Niederwieser) #9

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) #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)

}

}

}

}

}

}