dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
Bug: Throws exception in Android project with `localTest` and `local` build types
Build scan link
https://scans.gradle.com/s/iz5db3a77i22g
Plugin version
1.15.0
Gradle version
7.4.2
(Optional) Android Gradle Plugin (AGP) version
4.2.2
Describe the bug
When importing this plugin into an Android project with two custom buildType
s, localTest
and local
, doing anything Gradle-related like syncing the project in Android Studio or running ./gradlew tasks
causes this error message to be reported.
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.api.internal.tasks.DefaultTaskContainer$DuplicateTaskException: Cannot add task 'artifactsReportLocalTest' as a task with that name already exists.
> KotlinJvmAndroidCompilation with name 'local' not found.
The associated exception stack trace can be found in the Gradle Build Scan link above.
To Reproduce Steps to reproduce the behavior:
- Open the latest Android Studio (Android Studio Dolphin | 2021.3.1 Patch 1, at time of writing).
- Go to "File" > "New" > "New Project..."
- Select the "Phone and Tablet" > "No Activity" template and click "OK".
- Click "Finish", accepting the default project settings.
- In the root
build.gradle
, add the following line:
plugins {
// ...
id "com.autonomousapps.dependency-analysis" version "1.15.0"
}
- In
app/build.gradle
, add the following lines to theandroid
>buildTypes
section:
// ...
android {
// ...
buildTypes {
// ...
localTest {}
local {}
}
// ...
}
// ...
- Tap Ctrl+Ctrl and enter
gradle tasks
. Alternatively, run./gradlew tasks
from the terminal.
Expected behavior
The list of tasks for this project should appear.
Additional context
I was trying to apply this plugin to our proprietary Android app's Gradle build, where I first saw the error message and stack trace mentioned above. We have a number of Android build types, including local
and localType
, which would be impractical to remove or adjust.
Could you provide the reproducer? Either zip or git project would work. I'm not going to go through those manual steps. I know this plugin works with custom build types because lots of Android projects have custom build types (including mine) and the plugin works. So, something else is going on here.
Sure, no worries. You may find a reproducer at the following GitHub repo: https://github.com/jbduncan/dependency-analysis-android-gradle-plugin-bug-repro.
Ohh haha the issue is due to the names of your buildTypes. Because you have a buildType is named "localTest", the plugin tries to create a task with the slug LocalTest
. However, you also have a buildType named "local", which means the unit test analysis for the "local unit test" source will have the slug LocalTest
—identical to the other slug.
The simplest solution is to not use the suffix "test" in any of your build types. You could also rename the "local" buildType to something else.
It's unlikely that I will fix this in the plugin any time soon.
Ahh, gotcha!
I'll discuss this with my team, as I'm not sure of the consequences of renaming these build types, or if we even need them. Regardless, we could always temporarily rename them whilst trying out this plugin, and we have a couple of other apps that don't have build types like these, so we'd still benefit from this plugin, I imagine.
Many thanks for looking into this, and for all your time and effort with this plugin and the other tools you maintain. I'm acutely aware how time-consuming open source work is, having contributed to open source on and off over the years. :)
I'll keep this issue open in case you ever find the time to fix it.