Update Gradle configuration to allow resolver to work with aar artifacts#1394
Update Gradle configuration to allow resolver to work with aar artifacts#1394cheister wants to merge 1 commit intobazel-contrib:masterfrom
Conversation
a9d4cb2 to
39148a1
Compare
| attributes { | ||
| attribute( | ||
| LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, | ||
| objects.named(LibraryElements, "aar") |
There was a problem hiding this comment.
My understanding is that this will only fetch AARs (or rather resolve them in the graph) and will break the default configuration of fetching JARs (from runtimeClassPath). I think this might break the other tests.
I thought I had fixed this test, my bad. But I think this could be resolved with an ArtifactView to fetch AARs explicitly. Looking at the gradle module metadata for this https://dl.google.com/android/maven2/androidx/compose/foundation/foundation-android/1.9.0-beta02/foundation-android-1.9.0-beta02.module the dependency constraints seem to be the same for this artifact across variants, just the variant is different with different attribute. You might be able to add something like (I haven't tested to be frank)
ArtifactView aars =
cfg.getIncoming()
.artifactView(
spec -> {
spec.setLenient(true);
spec.withVariantReselection(); // force variant reselection
spec.attributes(
attrs -> {
attrs.attribute(
LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
project.getObjects().named(LibraryElements.class, LibraryElements.AAR));
});
});
here and collect the AAR artifact https://github.com/bazel-contrib/rules_jvm_external/blob/master/private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/plugin/GradleDependencyModelBuilder.java#L319 and it should probably work and be additive.
A separate configuration would probably work too but it might need to additive from the default configuration. Both can probably be done here in the gradle file or in the plugin itself.
There was a problem hiding this comment.
I'm definitely open to other ways of fixing this.
I tried removing the changes to build.gradle.hbs and adding your changes:
+++ b/private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/plugin/GradleDependencyModelBuilder.java
@@ -53,6 +53,7 @@ import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.artifacts.result.UnresolvedDependencyResult;
import org.gradle.api.attributes.Attribute;
+import org.gradle.api.attributes.LibraryElements;
import org.gradle.api.attributes.Usage;
import org.gradle.tooling.provider.model.ToolingModelBuilder;
@@ -322,10 +323,14 @@ public class GradleDependencyModelBuilder implements ToolingModelBuilder {
spec -> {
spec.setLenient(true);
spec.attributes(
- attrs ->
- attrs.attribute(
- Usage.USAGE_ATTRIBUTE,
- project.getObjects().named(Usage.class, Usage.JAVA_API)));
+ attrs -> {
+ attrs.attribute(
+ Usage.USAGE_ATTRIBUTE,
+ project.getObjects().named(Usage.class, Usage.JAVA_API));
+ attrs.attribute(
+ LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
+ project.getObjects().named(LibraryElements.class, "aar"));
+ });
});
// collect JAR artifacts
but running REPIN=1 bazel run @regression_testing_gradle//:pin still fails with
com.github.bazelbuild.rules_jvm_external.resolver.remote.UriNotFoundException: Unable to download androidx.compose.animation:animation-core:1.2.1 from any of [https://repo1.maven.org/maven2, https://maven.google.com]. Required because: androidx.compose.animation:animation-core:1.2.1
at com.github.bazelbuild.rules_jvm_external.resolver.cmd.Main.lambda$fulfillDependencyInfos$1(Main.java:149)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Do you know if the ArtifactView works if Gradle says it failed to resolve the dependency with just regular Gradle?
For example if you create a build.gradle file:
apply plugin: 'java'
repositories {
maven {
url "https://repo1.maven.org/maven2"
allowInsecureProtocol = false
}
maven {
url "https://maven.google.com"
allowInsecureProtocol = false
}
}
dependencies {
implementation("androidx.compose.animation:animation-core:1.2.1")
}
and run gradle :dependencies --configuration runtimeClasspath it returns
runtimeClasspath - Runtime classpath of source set 'main'.
\--- androidx.compose.animation:animation-core:1.2.1 FAILED
which I assume means it didn't even try to download the aar file
There was a problem hiding this comment.
Let me take a quick look
There was a problem hiding this comment.
Ok I think I understand what's going on. It looks like Android depndencies don't even resolve in the dependency graph with gradle, so using ArtifactView might not help actually. We might have to try to incorporate the android plugin configuration in the gradle build file for this to resolve from the looks of it or use a detached configuration. I'm trying it now, it's a bit tricky, will report back if it works.
There was a problem hiding this comment.
Alright I think I was able to resolve it, with #1395. More details there
|
Closing in favor of #1395 |
cc: @smocherla-brex
The default gradle "implementation" configuration only resolves "jar" artifacts. I added a new configuration that also resolves "aar" artifacts but might be missing a better way to do this in Gradle?