Is there a way to allow a configuration to resolve...
# community-support
t
Is there a way to allow a configuration to resolve empty? Ie i would like Configuration.resolve() to return a emtpy Set if no suitable configuration is found or the configuration does not have any artifacts (composite build). Or is there a way to handle such cases somehow? Given the setup below Project A can declare a dependency on Project B using declaredConfiguration. This allows resolvedConfiguration1 to be correctly resolved to the relevant Artifacts. Project B however should not be required to provide an artifact matching resolvedConfiguration2. I want to resolve/use them if they exist but its ok if they dont. Currently i always get "No matching variant of project :projectB was found." errors.
Copy code
val declaredConfiguration: NamedDomainObjectProvider<Configuration> = configurations.register("declaredConfiguration") {
    isCanBeResolved = false
    isCanBeConsumed = false
}
val resolvedConfiguration1: Provider<Configuration> = configurations.register("resolvedConfiguration1") {
    isCanBeResolved = true
    isCanBeConsumed = false

    // attributes
    
    extendsFrom(declaredConfiguration.get())
}
val resolvedConfiguration2: Provider<Configuration> = configurations.register("resolvedConfiguration2") {
    isCanBeResolved = true
    isCanBeConsumed = false

    // different set of attributes

    extendsFrom(declaredConfiguration.get())
}
v
I'm not fully sure, a lenient configuration might do what you want. But if it behaves like a lenient attract view, it will also ignore things like download errors and so on. If you use an artifact view on the other hand and specify attributes on it, it will be ok if not all the dependencies provide that variant. For that you would not set the artifact view to lenient which would ignore all errors, but just set attributes on it. See also https://github.com/gradle/gradle/issues/30314