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

AdviceAggregateReportTask class cast exception #295

Closed
AlexBurdu opened this issue Oct 3, 2020 · 9 comments · Fixed by #301
Closed

AdviceAggregateReportTask class cast exception #295

AlexBurdu opened this issue Oct 3, 2020 · 9 comments · Fixed by #301
Labels
bug Something isn't working
Milestone

Comments

@AlexBurdu
Copy link

AlexBurdu commented Oct 3, 2020

AdviceAggregateReportTask crashes when trying to cast (dependency as ProjectDependency)

Plugin version
0.61.0

Gradle version
6.6.1

Android Gradle Plugin (AGP) version
4.2.0-alpha13 - yes, I know it's not supported yet

Describe the bug

Caused by: java.lang.ClassCastException: org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency_Decorated incompatible with org.gradle.api.artifacts.ProjectDependency
        at com.autonomousapps.tasks.AdviceAggregateReportTask.action(AdviceAggregateReportTask.kt:40)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)

To Reproduce
Steps to reproduce the behavior:
Running ./gradlew buildHealth fails with exception

Seems to happen because of a compileOnly dependency.

Expected behavior
Running ./gradlew buildHealth should gracefully handle unsupported dependencies

@autonomousapps
Copy link
Owner

Thanks for the report. I will take a look.

@autonomousapps
Copy link
Owner

@Burdu some questions

  1. Does it only happen with 4.2.0-alpha13, or also earlier versions of AGP?
  2. Do you have a reproducer? If not, can you describe your case more? You mentioned something to do with compileOnly, but it's unclear to me what would be happening here. Everything that reaches that point should be a ProjectDependency.

I can fix with with a safe cast, but I'd like to know how this could happen first.

@autonomousapps autonomousapps added the bug Something isn't working label Oct 3, 2020
@AlexBurdu
Copy link
Author

Unfortunately I can't test with AGP lower than alpha-13, as compilation will fail. I'm using jetpack compose alpha04, which is not backwards compatible.
I don't have a reproducer, as the project is internal and has a complex configuration.
I was thinking a quick fix is a check before the cast. If I identify more details, I'll post here.

@autonomousapps
Copy link
Owner

My concern is that it shouldn't be possible for something that isn't a ProjectDependency to reach that point. So I would like to understand the situation better.

You might also try debugging (instructions in wiki) to see what that dependency actually is.

@AlexBurdu
Copy link
Author

AlexBurdu commented Oct 4, 2020

OK, I found the cause.
I'm using gradle java-platform plugin to constraint versions on my modules' dependencies.
The java-platform module is called versions and I'm adding it as a composite build in settings.gradle:

includeBuild '../versions'

Then I'm using this module to constraint dependencies versions in every submodule from root gradle

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url = uri("https://jitpack.io") }
//        maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
    }

    this.afterEvaluate {
        applyVersionsConstraints(this)
    }
}

fun applyVersionsConstraints(project: Project) {
    val deps = project.dependencies
    project.configurations
        .filter { it.dependencies.isNotEmpty() }
        .forEach { config ->
            println("Adding Dependency: ${config.name} project(':versions')")
            deps.add(config.name, deps.platform(":versions"))
        }
}

image

@autonomousapps
Copy link
Owner

That's fascinating. I use platforms in my own projects, so I think this must have to do with it being an included build? I'll experiment a bit. Thanks a lot for the investigation.

@autonomousapps autonomousapps added this to the 1.0 milestone Oct 4, 2020
@autonomousapps
Copy link
Owner

Which plugins do you have applied in your versions project?

@autonomousapps
Copy link
Owner

I just replicated your configuration, based on this comment. I cannot replicate your issue. I'm willing to safe-cast, but I'd like to get to the bottom of this first, if you're willing. Do you have any plugins besides java-platform applied to your versions project?

@AlexBurdu
Copy link
Author

The versions project doesn't have any other plugin applied to it besides java-platform.

For the main project I have added to the classpath the following plugins, by declaring them to buildSrc deps:

dependencies {
    api platform(project(':versions'))

    implementation 'androidx.navigation:navigation-safe-args-gradle-plugin'
    implementation 'com.android.tools.build:gradle'
    implementation 'com.autonomousapps:dependency-analysis-gradle-plugin'
    implementation 'org.jetbrains.dokka:dokka-android-gradle-plugin'
    implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin'
    implementation 'org.jmailen.gradle:kotlinter-gradle'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants