Configuration-specific project dependencies not working with multiple artifacts


(Adam Elliott) #1

I have a project ‘a’ that declares two artifacts, each to its own configuration.Another project ‘b’ has two configurations, each depending on one of the configurations from ‘a’. When the configuration is resolved, both of the ‘b’ configurations wind up pointing to the same configuration of ‘a’. This started happening in gradle 1.7 and is also in 1.8. In version 1.6, they resolved to different files.

Project ‘a’:

configurations {
    configA1
    configA2
}
task A1jar(type: Jar) {
    archiveName = 'A1.jar'
    destinationDir = file("build/tmplibs")
}
task A2jar(type: Jar) {
    archiveName = 'A2.jar'
    destinationDir = file("build/tmplibs")
}
artifacts {
    configA1 A1jar
    configA2 A2jar
}

Project ‘b’:

configurations {
    configB1
    configB2
}
dependencies {
    configB1 project(path:':a', configuration:'configA1')
    configB2 project(path:':a', configuration:'configA2')
}
task dumpConfig << {
    println configurations.configB1.files
    println configurations.configB2.files
}

So I’m expecting output like this (which is what Gradle 1.6 does)

:b:dumpConfig
[/home/aelliott/tmp/projectbug/a/build/tmplibs/A1.jar]
[/home/aelliott/tmp/projectbug/a/build/tmplibs/A2.jar]

But instead 1.7 and 1.8 both print

:b:dumpConfig
[/home/aelliott/tmp/projectbug/a/build/tmplibs/A2.jar]
[/home/aelliott/tmp/projectbug/a/build/tmplibs/A2.jar]

The real-world scripts I have fail because these configurations are used to compile java code, and the classpath becomes incorrect.

Is this a bug, or were we using the artifacts incorrectly before? Thanks,

-Adam


(Peter Niederwieser) #2

Sounds like a bug that was fixed in a 1.8 RC. Can you double-check that you still have this problem with 1.8 final?


(Adam Elliott) #3

Yes, it’s happening on 1.8 final… I also tried the latest night build, 1.9-20130925220417+0000, same problem there too.


(Peter Niederwieser) #4

Confirmed and raised as GRADLE-2899. Thanks for reporting.


(Adam Elliott) #5

I tried this out in the latest nightbuild, and this specific test is working now, thanks. However, it fails with a slight variation… in project b, add both of the artifacts from a into the same configuration:

dependencies {
    configB1 project(path:':a', configuration:'configA1')
    configB1 project(path:':a', configuration:'configA2')
}
task dumpConfig << {
    println configurations.configB1.files.join("\n")
}

It will only print out one of these jars, not both… this is working in 1.6, but not 1.7, 1.8, or 1.10-20131009224447+0000.

Following the note on the bug, I tried putting a baseName on the artifacts in ‘a’ and that works around the issue.