Skip to content
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

Get Android variant compile classpath from compileConfiguration #5152

Merged
merged 2 commits into from Sep 22, 2022

Conversation

3flex
Copy link
Collaborator

@3flex 3flex commented Jul 31, 2022

Fixes #5150

We don't have good functional test coverage for Android so we're not guarded against introducing new issues. However the implementation of getCompileConfiguration() calls getVariantData().getVariantDependencies().getCompileClasspath(), so without digging further into AGP internals this should provide equivalent results to the previous variant.getCompileClasspath(null) method.

@3flex 3flex marked this pull request as ready for review July 31, 2022 03:16
Using compileClasspath didn't resolve the right values at the right point
during configuration phase, causing problems with the configuration cache.

Fixes detekt#5150
variant.getCompileClasspath(null).filter { it.exists() },
variant.compileConfiguration.incoming.artifactView { view ->
view.attributes {
it.attribute(Attribute.of("artifactType", String::class.java), "jar")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why do we need to restrict on this attribute?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it there's a long error from Gradle for multiple detekt tasks. The reason is outlined in this comment: gradle/gradle#5953 (comment), specifically:

There is no single artifact for an Android project. Each project provides an AARs, a JAR, a classes folder, a resources folder etc). The Android team decided not to have a default fallback to prevent silent failures.

And gradle/gradle#5953 (comment)

as a consumer you need to be explicit what you are interested in. Do you want classes, resources, manifests, whole AAR files etc.

The error:

    Could not determine the dependencies of task ':app:detektTest'.
    > Could not create task ':app:detektDebugAndroidTest'.
       > Could not resolve all files for configuration ':app:debugAndroidTestCompileClasspath'.
          > The consumer was configured to find an API of a component, 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 '7.2.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :app:
              - Configuration ':app:debugApiElements' variant android-base-module-metadata declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-base-module-metadata' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-feature-all-metadata declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-feature-all-metadata' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-feature-res-ap_ declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-feature-res-ap_' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-feature-signing-config-data declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-feature-signing-config-data' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-feature-signing-config-versions declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-feature-signing-config-versions' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-java-res declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-java-res' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it
              - Configuration ':app:debugApiElements' variant android-manifest-metadata declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
                  - Unmatched attributes:
                      - Provides attribute 'artifactType' with value 'android-manifest-metadata' but the consumer didn't ask for it
                      - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
                      - Provides a library but the consumer didn't ask for it

@3flex 3flex mentioned this pull request Sep 20, 2022
@BraisGabin BraisGabin merged commit 505d6d7 into detekt:main Sep 22, 2022
19 checks passed
@3flex 3flex deleted the 5150-fix branch September 22, 2022 22:08
@cortinico cortinico added this to the 1.22.0 milestone Sep 23, 2022
BraisGabin pushed a commit that referenced this pull request Nov 5, 2022
* Revert behaviour change from 505d6d7

* Use standard getter to determine CLI arguments

This avoids the issue with configuration cache originally reported in
#5150, while keeping the v1.21 method of determining the classpath for the
generated detekt tasks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1.21.0: IllegalArgumentException: File/directory does not exist: IdentityTransform.transform
3 participants