Hi all, I needed gradle to create pom's that would add exclusion clauses to
dependencies that we have marked as non-transitive in our dependencies
section.
After some digging around I ended up with the following build script which
gets me what I wanted.
However I can't feel but there is a simpler way to achieve this so I'm
posting here in the hope that someone could give me some pointers if I'm
barking up the wrong tree.
I used 1.0-M3.
build.gradle:
apply plugin: 'nexusBuild'
version = 1.0
dependencies {
compile 'log4j:log4j:1.2.13'
compile('jaxen:jaxen:1.1.1') {
transitive = false
}
}
afterEvaluate {
nonTransitiveDeps = configurations.all*.dependencies*.findAll {
!it.transitive }.flatten()
}
uploadArchives.repositories.whenObjectAdded {
it.pom.whenConfigured {pom ->
pom.dependencies.each {
if (nonTransitiveDeps.find({ dep -> dep.group == it.groupId}) !=
null) {
//I am always getting an 'unable to resolve class
org.apache.maven.model.Exclusion' error
//hence the strange constructor invocation
def exclusion =
pom.model.class.classLoader.loadClass("org.apache.maven.model.Exclusion").newInstance();
exclusion.setGroupId('*')
exclusion.setArtifactId('*')
it.addExclusion(exclusion)
}
}
}
}
the pom generated is:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="
http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>calidris</groupId>
<artifactId>dummy</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
* <exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>*
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
nexusBuild plugin is a plugin that sets up repositories for uploading and
downloading depending on parameter(snapshot/release) + adding the java
plugin + some other minor stuff.