iwarapter / gradle-sonar-packaging-plugin

Gradle Plugin for building SonarQube plugins.
Other
19 stars 11 forks source link

0.1.4: the plugin fails to account for gradle 2.12's new (and longly awaited) compileOnly #13

Open fge opened 8 years ago

fge commented 8 years ago

See here:

https://docs.gradle.org/current/release-notes#support-for-declaring-compile-time-only-dependencies-with-java-plugin

This means that in theory, we do not have to declare anymore a new provided configuration and use that for the sonar-plugin-api jar.

If I try and use compileOnly for the sonar-plugin-api jar, the plugin says that the jar cannot be found.

iwarapter commented 8 years ago

Im just thinking about the best way to support this, will need to refactor a little.

otrosien commented 7 years ago

Are still on this? I could as well try to provide a PR.

iwarapter commented 7 years ago

Hi @otrosien, I had a little play with this awhile back and it wasnt quite as clear cut. Will did it back up and have another go!

otrosien commented 7 years ago

Nowadays compileOnly should just be taken as granted. or do you plan to support gradle versions older than 2.12?

iwarapter commented 7 years ago

I have released 1.0-RC1 this supports compileOnly, can you give it a go please :)

arturbosch commented 7 years ago

As mentioned in #19 provided works for me now but compileOnly fails with:

Jun 27, 2017 10:25:54 AM org.junit.platform.commons.util.ClasspathScanner logWarning
WARNING: Failed to load java.lang.Class for path [/home/artur/Repos/detekt/detekt-sonar-kotlin/build/classes/java/main/io/gitlab/arturbosch/detekt/sonar/DetektSensor.class] during classpath scanning.
java.lang.NoClassDefFoundError: org/sonar/api/batch/sensor/Sensor
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.junit.platform.commons.util.ReflectionUtils.loadClass(ReflectionUtils.java:357)
    at org.junit.platform.commons.util.ClasspathScanner.processClassFileSafely(ClasspathScanner.java:156)
    at org.junit.platform.commons.util.ClasspathScanner.lambda$findClassesForPath$3(ClasspathScanner.java:141)
    at org.junit.platform.commons.util.ClassFileVisitor.visitFile(ClassFileVisitor.java:41)
    at org.junit.platform.commons.util.ClassFileVisitor.visitFile(ClassFileVisitor.java:24)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at java.nio.file.Files.walkFileTree(Files.java:2742)
    at org.junit.platform.commons.util.ClasspathScanner.findClassesForPath(ClasspathScanner.java:141)
    at org.junit.platform.commons.util.ClasspathScanner.findClassesForUri(ClasspathScanner.java:125)
    at org.junit.platform.commons.util.ClasspathScanner.scanForClassesInClasspathRoot(ClasspathScanner.java:103)
    at org.junit.platform.commons.util.ReflectionUtils.findAllClassesInClasspathRoot(ReflectionUtils.java:514)
    at org.junit.platform.commons.util.ReflectionUtils.findAllClassesInClasspathRoot(ReflectionUtils.java:504)
    at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:66)
    at org.jetbrains.spek.engine.SpekTestEngine.discover(SpekTestEngine.kt:50)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:115)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:87)
    at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:65)
    at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57)
    at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
    at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57)
    at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:79)
    at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:69)
    at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:41)
Caused by: java.lang.ClassNotFoundException: org.sonar.api.batch.sensor.Sensor
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 35 more

I'm using Junit5 and Spek as their callstack is mentioned.

iwarapter commented 7 years ago

@arturbosch i cant reproduce this on your project, here is my diff:

diff --git a/detekt-sonar-kotlin/build.gradle b/detekt-sonar-kotlin/build.gradle
index 355455c..9ded9b6 100644
--- a/detekt-sonar-kotlin/build.gradle
+++ b/detekt-sonar-kotlin/build.gradle
@@ -12,7 +12,7 @@ dependencies {
        compile project(':detekt-core')
        compile project(':detekt-formatting')
        compile project(':detekt-rules')
-       provided "org.sonarsource.sonarqube:sonar-plugin-api:$sonarVersion"
+       compileOnly "org.sonarsource.sonarqube:sonar-plugin-api:$sonarVersion"
        testCompile "org.sonarsource.sonarqube:sonar-testing-harness:$sonarVersion"
        testRuntime "org.junit.platform:junit-platform-launcher:$junitPlatformVersion"
        testRuntime "org.junit.platform:junit-platform-console:$junitPlatformVersion"
@@ -39,4 +39,4 @@ sonarPackaging {
        skipDependenciesPackaging = false
        useChildFirstClassLoader = false
        basePlugin = ''
-}
\ No newline at end of file
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index adad9d2..c0a2144 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
arturbosch commented 7 years ago

Ok I analyzed the behaviour again: I get the exceptions but they do not make the build fail. I can localDeploy and restartServer and everything works (just the stacktraces). Idk what is wrong, I will just use provided ^^

iwarapter commented 7 years ago

OK so the plugin extends compile with the provided configuration, as such when its provided your tests are also getting the class in the classpath. However when using compileOnly this wasnt happening for your tests (the plugin still works as expected creating the jar). Since they have started seperating out the various configurations (especially with kotlin) i'll have a think and see if there is a better way to handle this.

otrosien commented 7 years ago

@iwarapter maybe it's a case of trying to do too much.. Inside build.gradle you usually have the sonarqube version, maybe even as an ext-parameter. So why infer the version from the dependencies if the user can just pass it as string property?

iwarapter commented 7 years ago

@otrosien it's not just a case of knowing the version unfortunately, its used to identify all the jars that are part of it and hence don't need to be packaged in the plugin. I just need to check with the recent split of configurations whats the best approach.

otrosien commented 7 years ago

@iwarapter isn't that what compileOnly is for? No need to reinvent the wheel..