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

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

Open
fge opened this issue Mar 31, 2016 · 12 comments
Assignees
Milestone

Comments

@fge
Copy link
Contributor

fge commented Mar 31, 2016

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 iwarapter self-assigned this Mar 31, 2016
@iwarapter
Copy link
Owner

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

@otrosien
Copy link

otrosien commented Jun 3, 2017

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

@iwarapter
Copy link
Owner

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
Copy link

otrosien commented Jun 4, 2017

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

@iwarapter iwarapter added this to the 0.1.5 milestone Jun 14, 2017
@iwarapter
Copy link
Owner

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

@arturbosch
Copy link

arturbosch commented Jun 27, 2017

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
Copy link
Owner

@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

@iwarapter iwarapter modified the milestones: 0.1.5, 1.0 Jun 28, 2017
@arturbosch
Copy link

arturbosch commented Jun 28, 2017

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
Copy link
Owner

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
Copy link

@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
Copy link
Owner

@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
Copy link

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

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

4 participants