jfrog / jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
Apache License 2.0
536 stars 234 forks source link

jf audit gradle error on android project #1610

Closed gregoryboue closed 2 years ago

gregoryboue commented 2 years ago

Describe the bug

On android project with gradle 7.3.3 and com.android.tools.build:gradle:7.2.1, jf audit command produce following error :

Task :app:extractModuleInfo
Error during extraction: 
org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':app:debugAndroidTestCompileClasspath'.
 at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.wrapException(ErrorHandlingConfigurationResolver.java:105)
...
Caused by: org.gradle.internal.component.AmbiguousVariantSelectionException: 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'. 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, 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':
       - 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
          - Doesn't say anything about its target Java environment (preferred optimized for Android)
....

To Reproduce

Expected behavior

a jf audit execution without errors and functionnal project dependency scan

Versions

Additional context

It seems that variant production (debug, release) is root cause, if i update modules configuration in root build.gradle as following, it works : artifactoryPublish.dependsOn('build') -> artifactoryPublish.dependsOn('assembleDebug') or artifactoryPublish.dependsOn('assembleRelease').

This problem also affect jf build scan command because no dependency information are collected in build-info when i perform a jf gradle build.

gregoryboue commented 2 years ago

Hi,

Any news about this ?

gregoryboue commented 2 years ago

This problem was due to an artifactory publications artifact misconfiguration, i close the issue

Larnoo commented 2 years ago

i have the same problem. How did you work it out?

gregoryboue commented 2 years ago

you have to configure your publishing.publications block to publish only one buildType :

publishing {
    publications {
        app(MavenPublication) {
            groupId = group
            artifactId = project.getName()
            version = version
// only debug apk
            artifact("$buildDir/outputs/apk/debug/${project.getName()}-debug.apk")...
}

    artifactoryPublish.dependsOn('assemble')
    artifactoryPublish {
        publications(publishing.publications.app)
    }

or you can configure one publication by builldType and add this publications in artifactoryPublish

publishing.publications {
    android.applicationVariants.all { variant ->
         "maven${variant.name.capitalize()}Apk"(MavenPublication) {
               // artifact configurations here
          }
     }
}

artifactoryPublish.dependsOn("assemble")

artifactoryPublish {
     android.applicationVariants.all { variant ->
        if (variant.name.contains("${flavour}${currentJob.capitalize()}")) {
            publications("maven${variant.name.capitalize()}Apk")
        }
    }
}
a735131232 commented 1 year ago

gradle 7.5 com.android.tools.build:gradle:7.4.1 "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"

错误信息,请问这个错误如何解决? image

配置内容,多项目 app + library 在一个project下,只配置 APP 主项项目 image