When overriding the target of a dependency, this is not reflected in POMs produced by the maven-publish plugin


(tim.wright) #1

I am putting togther a system which automatically translates project references with versions published by previous jobs on a CI server to automate production of versioned builds from a codebase. To do this I am using the configuratoins resolutionStrategy.eachDependency method. However, when using the maven-publish plugin, the POM file generated is not using this resolution strategy to replace the dependency and instead (I assume from the output) is looking at the raw original dependencies.

Running gradle build generatePomFileForMavenJavaPublication on the following is a contrived example:

apply plugin: 'java'
apply plugin: 'maven-publish'
  sourceCompatibility = 1.5
version = '1.0'
  repositories {
    mavenCentral()
}
  dependencies {
    compile 'org.slf4j:log4j-over-slf4j:SNAPSHOT'
}
  configurations.all {
    resolutionStrategy.eachDependency { details ->
        println 'processing ' + details.target
        details.useTarget 'org.slf4j:log4j-over-slf4j:1.7.5'
    }
}
  publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

The generated pom file will contain a reference to the SNAPSHOT version. Similarly if replacing a project reference with a repo co-ordinate the same thing happens.

Is this intended behaviour, it seems wrong. How could I resolve this and generate the correct pom for my purposes. (Have not looked at a suitable workaround yet!)

Tim Wright