I’m not sure if this is a known issue, but I want to be clear. It appears that MavenPublication.from reads the dependencies directly, instead of the resolved configuration, meaning that any eachDependency lines are ignored when publishing.
Here’s an example:
apply plugin: 'java'
apply plugin: 'maven-publish'
group = 'test'
version = '1.0'
repositories { jcenter() }
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
dependencies {
compile 'com.google.guava:guava:16.0'
}
configurations.all {
resolutionStrategy {
eachDependency { details ->
if (details.requested.name == 'guava') {
details.useTarget group: details.requested.group, name: 'guava-tests-jdk5', version: details.requested.version
}
}
}
}
run “gradlew publishToMavenLocal” and look at ~/.m2/repository/test/resolution-strategy-publish/1.0/resolution-strategy-publish-1.0.pom. It has guava instead of guava-tests-jdk5, even though that the resolved configuration shows. E.g.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0</version>
<scope>runtime</scope>
</dependency>
When the gradle dependencies shows
runtime - Runtime classpath for source set 'main'.
\--- com.google.guava:guava:16.0 -> com.google.guava:guava-tests-jdk5:16.0
\--- com.google.code.findbugs:jsr305:1.3.9
I tried a few versions of gradle, including 2.0-rc-2 and it seems to alway be there. Can someone confirm that this is true?