autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Bug: Throws exception in Android project with `localTest` and `local` build types

Open
#818 4 comments 0 reactions 0 assignees View on GitHub
bug sponsorable toolchain:android
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**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:
1. Open the latest Android Studio (_Android Studio Dolphin | 2021.3.1 Patch 1_, at time of writing).
2. Go to "File" > "New" > "New Project..."
3. Select the "Phone and Tablet" > "No Activity" template and click "OK".
4. Click "Finish", accepting the default project settings.
5. In the root `build.gradle`, add the following line:
```groovy
plugins {
// ...
id "com.autonomousapps.dependency-analysis" version "1.15.0"
}
```
6. In `app/build.gradle`, add the following lines to the `android` > `buildTypes` section:
```groovy
// ...

android {
// ...

buildTypes {
// ...

localTest {}

local {}
}

// ...
}

// ...
```
8. 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.

Contributor guide

Open the contributing guide

Research direction

Start with the root build.gradle and app/build.gradle reproduction, then review the linked Gradle Build Scan and run ./gradlew tasks with localTest and local build types. The work is done when the project evaluates successfully and the task list appears without the duplicate artifactsReportLocalTest or missing KotlinJvmAndroidCompilation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
build-system, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.