Skip to content

Commit

Permalink
Reduce noise of AmbiguousArtifactVariantsException logs even more
Browse files Browse the repository at this point in the history
The content of the `AmbiguousArtifactVariantsException` `message` is the following:
```
The consumer was configured to find a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.4.0', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.ProductFlavor:appType' with value 'standalone', attribute 'com.android.build.api.attributes.ProductFlavor:endpoint' with value 'dev', attribute 'com.android.build.api.attributes.ProductFlavor:platform' with value 'androidtv', attribute 'com.android.build.api.attributes.ProductFlavor:tenant' [...]
  [...]
  - Configuration
  [...]
  - Configuration ':coreUi:tenantADebugRuntimeElements' variant supported-locale-list declares a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.4.0', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.ProductFlavor:tenant' with value 'tenantA', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Doesn't say anything about com.android.build.api.attributes.ProductFlavor:appType (required 'standalone')
          - Doesn't say anything about com.android.build.api.attributes.ProductFlavor:endpoint (required 'dev')
          - Doesn't say anything about com.android.build.api.attributes.ProductFlavor:platform (required 'androidtv')
          - Provides attribute 'artifactType' with value 'supported-locale-list' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'tenantADebug' but the consumer didn't ask for it
          - Provides attribute 'tenant' with value 'tenantA' but the consumer didn't ask for it
```

So printing the `message` of this exception is also adding a lot of noise to the Gradle logs. It can take up to 157 lines when using four Android Flavors. And this exception is thrown multiple times. In the case of four Flavors 30 times (30*157=4710 lines).

Also the `isDebugEnabled` condition is seemingly inverted. Printing the exception stacktrace for non-debug logs is likely unwanted.

Since `warn` is always printed (`isWarnEnabled` is always `true`) this (expected) exception should only be printed on higher log levels:
* `isInfoEnabled` (enabled via Gradle `--info` CLI parameter) includes only an hint that there's an ambiguity in the resolved config, and *no* details
* `isDebugEnabled` (enabled via Gradle `--debug` CLI parameter) includes the complete exception with all the details
  • Loading branch information
exaring-android-service committed May 22, 2024
1 parent c948f79 commit 77359c8
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ class DependencyCollector(
}
}
} catch (e: Throwable) {
if (LOGGER.isDebugEnabled) {
LOGGER.warn("Found possibly ambiguous variant - $resolvedDependency - ${e.message}")
} else {
LOGGER.warn("Found possibly ambiguous variant - $resolvedDependency", e)
when {
LOGGER.isDebugEnabled -> {
LOGGER.warn("Found possibly ambiguous variant - $resolvedDependency", e)
}
LOGGER.isInfoEnabled -> {
LOGGER.warn("Found possibly ambiguous variant - $resolvedDependency")
}
}
}
}
Expand Down

0 comments on commit 77359c8

Please sign in to comment.