Dependency constraints always injected as dependencies

Hi,

I’m using Gradle 5.5 and the Kotlin DSL.

My real life example is more complex but I was able to isolate the issue in a very simple example at https://github.com/dcoraboeuf/gradle-constraints

Given a root module defined as:

subprojects {
   apply(plugin = "java-library")
   dependencies {
     // Spring Boot managed dependencies
     "implementation"(platform("org.springframework.boot:spring-boot-dependencies:1.5.18.RELEASE"))
     // Constraints
     constraints {
       "implementation"("args4j:args4j:2.33")
     }
  }

}

and a submodule defined as:

val copyDependencies by tasks.registering(Copy::class) {
    into("build/dependencies")
    from(configurations.runtimeClasspath)
}

When I run ./gradlew :module:copyDependencies, I would expect the args4j dependency to NOT be copied because it is defined only as a constraint and not declared explicitly by my module.

However, it DOES get copied over:

> ls -l module/build/dependencies 
total 304
-rw-r--r--  1 damiencoraboeuf  staff   152K Jul  8 14:39 args4j-2.33.jar

I wonder what I’m doing wrong. I want to simulate a local platform behaviour.

Best regards, and thanks for any help,
Damien

This looks like it could be a bug in the accessor/operator. Since you’re using apply and having to quote "implementation", it looks like it’s calling add on dependencies, not constraints. I would probably report this issue on the GitHub issue tracker, but if you just want to see it work, changing the constraint to call add() should work:

constraints {
    add("implementation", "args4j:args4j:2.33")
}