Maven-publish plugin does not add excludes to generated pom

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)

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

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

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

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.

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.

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.

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

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)

}

}

}

}

}

}