New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detached configurations cannot extend from existing configurations #6881
Comments
FWIW, there's a first problem which is that detached configurations cannot inherit from configurations defined in a different container. So, in fact, we get no dependencies because we don't inherit dependencies from the parent configuration here. |
Yes, I can confirm it works properly if we include the set of configurations from the container the detached configuration was created from in the list. |
Updated the title to reflect the real problem |
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution. |
This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request. |
counter++ I think I hit this the second or the third time already |
Interesting. I have tried creating a detached configuration that extends from another detached configuration, both from the same configuration container. The first configuration contains a dependency without a Problem observed when using Gradle 7.1.1. |
I stumbled across the same issue and described it on the forum here: def newConfiguration = project.configurations.detachedConfiguration()
newConfiguration.setCanBeResolved(true)
newConfiguration.extendsFrom(project.configurations.runtimeClasspath) Resolving results in an empty array: doFirst {
println newConfiguration.resolve()
} So this issue gets a +1 from me. Would love to see this one resolved. Workaround is to create a attached configuration. |
This problem is a little painful when trying to resolve the non-transitive elements of a configuration. The suggested workaround #14880 is to create a non-transitive Configuration that extends the transitive Configuration. It would be nice to create the intransitive Configuration as detached, so it does not get confused with the transitive configuration, generate unnecessary Kotlin DSL accessors, or pollute IDE auto-completion. Here is an example that reproduces the problem. Copy it into a
It should list the declared dependency, and the transitive dependencies, and then finally the declared dependency. However, the detached and attached intransitive configurations produce different results
import org.gradle.api.attributes.Bundling.BUNDLING_ATTRIBUTE
import org.gradle.api.attributes.Bundling.EXTERNAL
import org.gradle.api.attributes.Category.CATEGORY_ATTRIBUTE
import org.gradle.api.attributes.Category.LIBRARY
import org.gradle.api.attributes.LibraryElements.JAR
import org.gradle.api.attributes.LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE
import org.gradle.api.attributes.Usage.JAVA_RUNTIME
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE
import org.gradle.api.attributes.java.TargetJvmEnvironment.STANDARD_JVM
import org.gradle.api.attributes.java.TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE
plugins {
base
}
val generatorPlugins by configurations.registering {
isCanBeResolved = true
isCanBeConsumed = false
isVisible = false
attributes {
attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME))
attribute(CATEGORY_ATTRIBUTE, objects.named(LIBRARY))
attribute(BUNDLING_ATTRIBUTE, objects.named(EXTERNAL))
attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(STANDARD_JVM))
attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(JAR))
}
}
val generatorPluginsIntransitiveAttachedConfiguration = configurations.create("generatorPluginsIntransitive") {
isCanBeResolved = true
isCanBeConsumed = false
isVisible = false
isTransitive = false
extendsFrom(generatorPlugins.get())
attributes {
attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME))
attribute(CATEGORY_ATTRIBUTE, objects.named(LIBRARY))
attribute(BUNDLING_ATTRIBUTE, objects.named(EXTERNAL))
attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(STANDARD_JVM))
attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(JAR))
}
}
val generatorPluginsIntransitiveDetachedConfiguration = configurations.detachedConfiguration().apply {
isCanBeResolved = true
isCanBeConsumed = false
isVisible = false
isTransitive = false
extendsFrom(generatorPlugins.get())
attributes {
attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME))
attribute(CATEGORY_ATTRIBUTE, objects.named(LIBRARY))
attribute(BUNDLING_ATTRIBUTE, objects.named(EXTERNAL))
attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(STANDARD_JVM))
attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(JAR))
}
}
dependencies {
"generatorPlugins"("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
val listPlugins by tasks.registering {
inputs.files(generatorPlugins)
doLast {
generatorPlugins.get().files.forEach { println(it.name) }
}
}
val listPluginsIntransitive by tasks.registering {
dependsOn(listPlugins)
inputs.files(generatorPluginsIntransitiveAttachedConfiguration)
inputs.files(generatorPluginsIntransitiveDetachedConfiguration)
doLast {
val attachedResult = generatorPluginsIntransitiveAttachedConfiguration.files.joinToString { it.name }
val detachedResult = generatorPluginsIntransitiveDetachedConfiguration.files.joinToString { it.name }
require(attachedResult == detachedResult) {
"""
attached: $attachedResult
detached: $detachedResult
""".trimIndent()
}
}
}
|
I just hit this bug yesterday and had to work around it by sort of manually copying the dependencies from the configuration I wanted to extend. |
We should fix this by failing fast instead of failing silently. |
Why?, The detached configuration is created from a given container, restricting it from extending configuration reachable through that container, seems like an arbitrary blocker. |
I agree that ideally this shouldn't fail but simply make it work. I guess that what Justin is saying is that it is currently broken anyway, so making it fail is a "better" solution in the sense that it would fail eagerly instead of being simply ignored. However it is reasonable to expect that this feature works. |
Context
Dependency resolution using attribute matching doesn't work if the configuration being resolved is a detached configuration. I'm actually surprised we went that far without fixing this. Given the following build file:
I would expect the
detached.files
collection to be the same ascompileClasspath.files
, given that it asks for the same attributes and both extendimplementation
. However, in practice, the collection is empty. Replacingconfigurations.detachedConfiguration()
withconfiguration.create("foo")
solves the problem, indicating that the issue is really with detached configurations, not with attribute matching.The text was updated successfully, but these errors were encountered: