dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
Could not resolve all task dependencies for configuration
Plugin version 1.28.0 (and 1.29.0)
Gradle version 8.2
JDK version 17
(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version Kotlin 1.9.21
(Optional) Android Gradle Plugin (AGP) version 8.2.1
Describe the bug
After bumping to 1.28.0 we get this error when building the project (for instance via build):
Could not determine the dependencies of task ':moduleA:extractDebugAnnotations'.
> Could not resolve all task dependencies for configuration ':moduleA:debugCompileClasspath'.
> Could not resolve project :moduleB.
Required by:
project :moduleA
> The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.2.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :moduleB:
- projectHealthElements
- resolvedDepsElements
All of them match the consumer attributes:
- Variant 'projectHealthElements' capability rootProject:moduleB:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.1')
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Provides attribute 'dagp.internal.artifacts' with value 'project-health' but the consumer didn't ask for it
- Doesn't say anything about its component category (required a library)
- Doesn't say anything about its target Java environment (preferred optimized for Android)
- Doesn't say anything about its usage (required compile-time)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
- Variant 'resolvedDepsElements' capability rootProject:moduleB:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.1')
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Provides attribute 'dagp.internal.artifacts' with value 'resolved-deps' but the consumer didn't ask for it
- Doesn't say anything about its component category (required a library)
- Doesn't say anything about its target Java environment (preferred optimized for Android)
- Doesn't say anything about its usage (required compile-time)
- Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
moduleA is here a regular module (with plugin com.android.library) and moduleB is a "wrapper" around an AAR file to be able to use it. The AAR file is included like this:
configurations.maybeCreate("default")
artifacts.add("default", file('someExternalLib.aar'))
This is not how the official documentation states it, but due to a weird bug this doesn't work for other reasons unfortunately.
I don't know if we can fix this in any other ways (is it possible to ignore dependencies or modules somehow?), so wanted to file this bug if you weren't aware of this. And for the record, it works fine for version 1.27.0.
Just for the record, I've now submitted a bug report for the solution stated by the official documentation. Hopefully it will get fixed, but it might still be worth figuring out why the other setup mentioned above doesn't work.
I think that other configuration you create needs to have some metadata attached to it. If you provide a reproducer I can take a look and see if there's something I can do in DAGP.
I've just resolved another issue that looks at least superficially similar. Could you try the latest snapshot (wait at least an hour from when I post this message)?
Hey @autonomousapps,
Thanks for the update. Unfortunately, I've tested 1.31.1-SNAPSHOT and it didn't solve this issue. At least on my side.
Alright, thanks! Looks like something that might be Android-specific.
I was able to workaround this by adding this to the top of the "wrapper" module:
// wrapper-module/build.gradle
plugins {
id("java")
}
I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?
For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.
For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.
What exactly throws a lint error?
Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:
> Failed to notify project evaluation listener.
> org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity
> KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.
Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:
> Failed to notify project evaluation listener. > org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity > KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.
@bidrohi this looks like a different issue. Could you file a new report?
I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?
We have an AAR-file that we have to import to our build somehow in order to be able to use it. We're okay about changing the way we import it (as long as it's reliable), but I'm not sure how you would add that as a dependency directly? Most other methods I've found is either outdated or not stable to use, unfortunately.
I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?
We have an AAR-file that we have to import to our build somehow in order to be able to use it. We're okay about changing the way we import it (as long as it's reliable), but I'm not sure how you would add that as a dependency directly? Most other methods I've found is either outdated or not stable to use, unfortunately.
Does a workaround like this help? Alternatively, you could publish that AAR to an internal artifact repo and consume it that way.
Does a workaround like this help?
Yeah, sorry forgot to give an answer here. I tried that, but I then wasn't able to access the content of the aar-file (imports of classes wasn't found anymore). It might be possible to do something like that, but I'm not an expert in gradle unfortunately.
Alternatively, you could publish that AAR to an internal artifact repo and consume it that way.
Might be an idea we could test out a bit. We are however several developers working on this project so we would need to have some automatic setup for this 🤔
This works for me:
apply plugin: 'kotlin'
dependencies {
api(files("someExternalLib.aar"))
}
This works for me:
apply plugin: 'kotlin' dependencies { api(files("someExternalLib.aar")) }
This looks much more "normal" to me!
For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.
What exactly throws a lint error?
Sorry.. I didn't share the lint error before:
Execution failed for task ':moduleA:bundleDebugLocalLintAar'.
> Error while evaluating property 'hasLocalAarDeps' of task ':moduleA:bundleDebugLocalLintAar'.
> Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :moduleA project caused this error: <path to aar>
Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:
> Failed to notify project evaluation listener. > org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity > KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.@bidrohi this looks like a different issue. Could you file a new report?
Looks like it was broken with Kotlin 1.9.0 updating to 1.9.24 resolved this issue.
This works for me:
apply plugin: 'kotlin' dependencies { api(files("someExternalLib.aar")) }
The issue with this solution is that it unfortunately gives and error when linting as mentioned in the original post. I have submitted an issue (see first answer), but I unfortunately don't think that will be fixed any time soon.
unfortunately gives and error when linting
can that lint error be excluded?
unfortunately gives and error when linting
can that lint error be excluded?
Considering that the lint is provided to catch actual issues with including some AARs, I would rather we don't
unfortunately gives and error when linting
can that lint error be excluded?
It's not a lint warning, the linter itself can't run. I think I would have to exclude the aar from the linting, but not sure if that's possible at all 🤔 To be honest, the best would be if Google fixed the issue - but I don't have my hopes that high.