Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude dependencies in the POM file generated by the Gradle

I'm using the "maven" plugin to upload the artifacts created by Gradle build to Maven central repository. I'm using a task similar to the following one:

uploadArchives {
  repositories {
    mavenDeployer {
      beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

      pom.project {
        name 'Example Application'
        packaging 'jar'
        url 'http://www.example.com/example-application'

        scm {
          connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'

          url 'http://foo.googlecode.com/svn/trunk/'
        }

        licenses {
          license {
            name 'The Apache License, Version 2.0'
            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          }
        }

      }
    }
  }
}

However the POM file created by this task does not report correctly the dependencies that have been excluded in my Gradle build file. For example:

dependencies {
    compile('org.eclipse.jgit:org.eclipse.jgit.java7:3.5.2.201411120430-r') { exclude module: 'commons-logging' }
    compile('com.upplication:s3fs:0.2.8') { exclude module: 'commons-logging' }
}

How to have excluded dependencies managed correctly in the resulting POM file?

like image 307
pditommaso Avatar asked Mar 19 '15 14:03

pditommaso


People also ask

How do you exclude a dependency in Pom?

Exclude a dependency You can use a diagram to exclude a dependency from the project's POM. Select a dependency in the diagram window. From the context menu, choose Exclude. From the list, select the module (if any) where the exclusion definition will be added.

What is exclusion in POM xml?

Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId. When you build your project, that artifact will not be added to your project's classpath by way of the dependency in which the exclusion was declared.

How do I resolve Gradle dependencies?

Given a required dependency, with a version, Gradle attempts to resolve the dependency by searching for the module the dependency points at. Each repository is inspected in order. Depending on the type of repository, Gradle looks for metadata files describing the module ( .


1 Answers

You can simply override the dependencies of the pom by filtering out the unwanted dependencies, e.g. to exclude junit you can add the following lines to the mavenDeployer configuration:

pom.whenConfigured {
    p -> p.dependencies = p.dependencies.findAll { 
        dep -> dep.artifactId != "junit" 
    }
}
like image 94
Amnon Shochot Avatar answered Sep 30 '22 20:09

Amnon Shochot