How to extend from runtimeClasspath?

I am trying to extend from the runtimeClasspath configuration like so:

def newConfiguration = project.configurations.detachedConfiguration()
newConfiguration.setCanBeResolved(true)
newConfiguration.extendsFrom(project.configurations.runtimeClasspath)

However when I try to resolve the configuration, it does not contain the files of the runtimeClasspath:

doFirst {
    println newConfiguration.resolve()
}

Returns an empty array. Is there a way to create a configuration from the runtime classpath? I would like to then to remove a view dependencies and their transitive dependencies using newConfiguration.exclude.

It seems a detached configurations cannot extend from another configuration.
I don’t know whether this is inteded, but if you make the new configuration a named configuration, it works.
You should probably report that as issue.

Thanks Björn! You are right! Didn’t cross my mind to think that it is because it is a detachedConfiguration!

Meanwhile I found Detached configurations cannot extend from existing configurations · Issue #6881 · gradle/gradle · GitHub describing my issue.

Thanks!

1 Like