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

sonarqube fails to due GString args options #48

Open
PssbleTrngle opened this issue Jul 19, 2023 · 1 comment
Open

sonarqube fails to due GString args options #48

PssbleTrngle opened this issue Jul 19, 2023 · 1 comment

Comments

@PssbleTrngle
Copy link

When using together with the sonarqube plugin, a ClassCastException is thrown:

Caused by: java.lang.ClassCastException: class org.codehaus.groovy.runtime.GStringImpl cannot be cast to class java.lang.String (org.codehaus.groovy.runtime.GStringImpl is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @5fdef03a; java.lang.String is in module java.base of loader 'bootstrap')
	at org.sonarqube.gradle.JavaCompilerUtils.configureCompatibilityOptions(JavaCompilerUtils.java:92)
	at org.sonarqube.gradle.JavaCompilerUtils.extractConfiguration(JavaCompilerUtils.java:60)
	at org.sonarqube.gradle.JavaCompilerUtils.extractJavaCompilerConfigurationFromCompileTasks(JavaCompilerUtils.java:49)
	at org.sonarqube.gradle.SonarPropertyComputer.populateJdkProperties(SonarPropertyComputer.java:255)
	at org.sonarqube.gradle.SonarPropertyComputer.lambda$configureForJava$3(SonarPropertyComputer.java:220)
	at org.gradle.api.internal.collections.CollectionFilter$1.execute(CollectionFilter.java:59)
	at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:161)
	at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:203)
	at org.sonarqube.gradle.SonarPropertyComputer.configureForJava(SonarPropertyComputer.java:220)
	at org.sonarqube.gradle.SonarPropertyComputer.addGradleDefaults(SonarPropertyComputer.java:457)
	at org.sonarqube.gradle.SonarPropertyComputer.computeSonarProperties(SonarPropertyComputer.java:99)
	at org.sonarqube.gradle.SonarPropertyComputer.computeSonarProperties(SonarPropertyComputer.java:146)
	at org.sonarqube.gradle.SonarPropertyComputer.computeSonarProperties(SonarPropertyComputer.java:86)

The sonaqube plugin attempts to access the compiler args here, but expects a List<String>.

The mixingradle plugin sets compiler args here using a GString template.

Usually groovy should automatically call toString on them, but for some reason it does not seem to do it here, because the compiler arguments contain objects of type GString when inspected in the debugger.

This can also only be recreated on the first run and can be reproduced by applying both the mixingradle and the sonarqube plugin and running clean build sonar.

A call to toString on all template strings that are appended to the compiler args could solve this problem

@PssbleTrngle
Copy link
Author

Can be resolved by adding the following to the build.gradle.kts:

allprojects {
    tasks.compileJava.configure {
        doFirst {
            options.compilerArgs.replaceAll { it: Any ->
                it.toString()
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant