title: How to force variant selection withResolvedConfiguration.getResolvedArtifacts?
body: <p>I'm working with a large, multi-module Android application, and I'm trying to define a Gradle task that collects the jars of all runtime dependencies. I'm trying something like this in <code>app/build.gradle</code>:</p>
  <pre><code>task collectDeps {
      doLast {
          configurations.releaseRuntimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
                  // do stuff
          }
      }
  }
  </code></pre>
  <p>I've used this snippet in the past on other Java projects, so I know that it conceptually works; this is just my first time trying it on a project with multiple build types and/or variants.</p>
  <p>When run on the Android project, executing this task throws a variant resolution error:</p>
  <pre><code>Execution failed for task ':app:collectDeps'.
  &gt; Could not resolve all dependencies for configuration ':app:releaseRuntimeClasspath'.
     &gt; The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :myModule:
         - Configuration ':myModule:releaseRuntimeElements' variant android-aar-metadata declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
             - Unmatched attributes:
                 - Provides attribute 'artifactType' with value 'android-aar-metadata' but the consumer didn't ask for it
                 - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
                 - Provides a library but the consumer didn't ask for it
         - Configuration ':myModule:releaseRuntimeElements' variant android-art-profile declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
             - Unmatched attributes:
                 - Provides attribute 'artifactType' with value 'android-art-profile' but the consumer didn't ask for it
                 - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
                 - Provides a library but the consumer didn't ask for it
  </code></pre>
  <p>I've trimmed the error for brevity; there are ~20 variants in total. Note that <code>myModule</code> is a project dependency of the top-level app; if I remove that dependency, the error is the same but comes from a different module.</p>
  <p>I should also note here that every other build target works fine; the application is quite mature, and the only change I've made is to add this new task to <code>app/build.gradle</code>. So I assume there's <em>something</em> about the way I'm resolving the dependencies that Gradle doesn't like, but I'm struggling to figure out what, or how to resolve it.</p>
  <p>Googling this error is not very helpful; the Gradle documentation is quite vague about exactly <em>how</em> to resolve variants, and the solutions that are provided seem to focus on changing how dependencies are added to the project; but I don't necessarily want to do that, because the build works fine for every other use case.</p>
  <p>Ideally, I'd like to be able to force a variant for the resolution specifically within my <code>collectDeps</code> task (in fact, ideally <code>collectDeps</code> would be defined in a plugin). Is this possible to do?</p>
  <p>In case it matters, the build is using Gradle 7.2 and v7.1.1 of the Android Gradle Plugin</p>