xvik / gradle-quality-plugin

Gradle quality plugin for Java and Groovy
http://xvik.github.io/gradle-quality-plugin
MIT License
134 stars 11 forks source link

A problem occurred configuring project ':lib': TasksListenerService$Inject #112

Open hdghg opened 4 months ago

hdghg commented 4 months ago

Hello! I ran into an issue while trying to configure the quality plugin with spring-boot-plugin in multi-module build:

class ru.vyarus.gradle.plugin.quality.service.TasksListenerService$Inject cannot be cast to class ru.vyarus.gradle.plugin.quality.service.TasksListenerService (ru.vyarus.gradle.plugin.quality.service.TasksListenerService$Inject is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @1eeea369; ru.vyarus.gradle.plugin.quality.service.TasksListenerService is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @1a7e32df)

The build consists of 3 files: settings.gradle.kts:

include("app", "lib")

app/build.gradle.kts:

plugins {
    java
    id("org.springframework.boot").version("3.2.6").apply(false)
    id("ru.vyarus.quality") version "5.0.0"
}

lib/build.gradle.kts:

plugins {
    `java-library`
    id("ru.vyarus.quality") version "5.0.0"
}

url to repo: https://github.com/hdghg/gradle-quality-plugin-bugreport

hdghg commented 4 months ago

I was able to exclude the springboot from culprits, this configuration in app/build.gradle.kts still causes the error:

plugins {
    java
    id("ru.vyarus.quality") version "5.0.0"
}
buildscript {
    repositories {
        mavenCentral()
    }
}

Unfortunately, using subprojects {} syntax is not an option

xvik commented 4 months ago

Thank you very much for the sample project! I reproduced the problem and will look for the cause

xvik commented 4 months ago

A quick workaround is to create root build.gralde.kts with:

plugins {
    id("ru.vyarus.quality").version("5.0.0").apply(false)
}

And inside sub-projects (app, lib) remove plugin version:

plugins {
    `java-library`
    id("ru.vyarus.quality")
}

The main problem is a global gradle service, registered only once. With separate plugin registrations, second module could not match service class becuase it was loaded with different class loader. The fix above forces plugin loading in the root project so both sub-projects would use it from the same class loader (and so could use one gradle service).

I will see how to resolve this in the plugin itself, but it would take some time.