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:


I would expect:


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

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.


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.


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: ‘asNode()’ returns a ‘groovy.util.Node’ just like ‘groovy.util.XmlParser#parseText’ does. You can find some ‘XmlParser’ examples here:

(atschabu) #10

that should do the trick:

project.publishing {

publications {

mavenJar(MavenPublication) {


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() == && it.artifactId[0].text() ==


def xmlExclusions = xmlDep.exclusions[0]

if (!xmlExclusions) xmlExclusions = xmlDep.appendNode(‘exclusions’)

dep.excludeRules.each { ExcludeRule rule ->

def xmlExclusion = xmlExclusions.appendNode(‘exclusion’)


xmlExclusion.appendNode(‘artifactId’, rule.module)