How to eliminate dependencies in a POM file generated using Gradle

I use the "maven" plugin to upload artifacts created using the Gradle build to the Maven central repository. I am using a task similar to the following:

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 correctly report dependencies that were excluded in my Gradle build file. For instance:

 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 eliminate dependencies that are properly managed in the resulting POM file?

+5
source share
2 answers

The problem was that the group was not defined in the exclude definition, but only the module.

Adding both of these exceptions is added correctly to the POM file. For instance:

 compile('org.eclipse.jgit:org.eclipse.jgit.java7:3.5.2.201411120430-r') { exclude group: 'commons-logging', module: 'commons-logging' } compile('com.upplication:s3fs:0.2.8') { exclude group: 'commons-logging', module: 'commons-logging' } 
+3
source

You can simply override pom dependencies by filtering out unwanted dependencies, for example. 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" } } 
+6
source

Source: https://habr.com/ru/post/1215691/


All Articles