I have a gradle file that defines dependencies using wildcards:
dependencies {
compile 'ch.qos.logback:logback-core:1.1.+'
compile 'ch.qos.logback:logback-classic:1.1.+'
compile 'com.codahale.metrics:metrics-core:3.0.+'
...
}
When I use the maven-publish plugin to generate a pom I get:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.+</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.+</version>
<scope>runtime</scope>
</dependency>
Which (obviously) maven cannot deal with. How do I get the pom to only contain resolved version numbers? I tried to modify the pom closure using:
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'
//...
publishing {
repositories {
maven {
url "${mavenPublishRepo}"
credentials {
username mavenPublishUser
password mavenPublishPass
}
}
}
publications {
mavenJava(MavenPublication) {
artifactId "baseline-${project.name}"
from components.java
artifact srcJar {
classifier 'sources'
}
artifact docJar {
classifier 'javadoc'
}
pom.withXml {
def root = asNode()
// ...
// remove the dependency entries gradle inserts
// this is because gradle uses wildcard versions
// in a maven pom, making the artifact unusable
// in straight-up maven projects
root.dependencies.children.each { node -> root.dependencies.remove(node) }
// re-add dependencies with fully-qualified versions
def dependencies = root.dependencies[0]
project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies.each { dep ->
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', dep.moduleGroup)
dependency.appendNode('artifactId', dep.moduleName)
dependency.appendNode('version', dep.moduleVersion)
dependency.appendNode('scope', 'runtime')
}
}
}
}
}
}
But the maven-publish plugin simply adds the wildcard dependencies along with my fully-resolved ones