I am using maven build. When running the sonarqube using sonar runner, I got an error: java.lang.NoClassDefFoundError: org/junit/rules/TestRule
I build the plugin on open Jdk1.8 and run the sonarqube on open jdk11
The full stacktrace
ERROR: Error during SonarScanner execution
java.lang.NoClassDefFoundError: org/junit/rules/TestRule
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:84)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
at org.sonar.classloader.DefaultClassloaderRef.loadClassIfPresent(DefaultClassloaderRef.java:40)
at org.sonar.classloader.ClassRealm.loadClassFromParent(ClassRealm.java:147)
at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:35)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at com.nrift.sonar.rules.impl.CheckDuplicateRecordExceptionCollectionGetZero.loadClass(CheckDuplicateRecordExceptionCollectionGetZero.java:527)
at com.nrift.sonar.rules.impl.CheckDuplicateRecordExceptionCollectionGetZero.loadFoundClass(CheckDuplicateRecordExceptionCollectionGetZero.java:509)
at com.nrift.sonar.rules.impl.CheckDuplicateRecordExceptionCollectionGetZero.addCollectionIdentifier(CheckDuplicateRecordExceptionCollectionGetZero.java:427)
at com.nrift.sonar.rules.impl.CheckDuplicateRecordExceptionCollectionGetZero.visitVariable(CheckDuplicateRecordExceptionCollectionGetZero.java:164)
at org.sonar.java.model.declaration.VariableTreeImpl.accept(VariableTreeImpl.java:144)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:34)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVisitor.java:70)
at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:211)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:34)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(BaseTreeVisitor.java:52)
at com.nrift.sonar.rules.impl.CheckDuplicateRecordExceptionCollectionGetZero.visitCompilationUnit(CheckDuplicateRecordExceptionCollectionGetZero.java:111)
at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree.java:196)
at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
at com.nrift.sonar.rules.CustomBaseTreeVisitor.scanFile(CustomBaseTreeVisitor.java:83)
at org.sonar.java.model.VisitorsBridge.lambda$runScanner$0(VisitorsBridge.java:156)
at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:161)
at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:156)
at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:139)
at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:114)
at org.sonar.java.ast.JavaAstScanner.lambda$scan$0(JavaAstScanner.java:76)
at org.sonar.java.model.JParserConfig$FileByFile.parse(JParserConfig.java:225)
at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:74)
at org.sonar.java.JavaFrontend.scanAndMeasureTask(JavaFrontend.java:343)
at org.sonar.java.JavaFrontend.scan(JavaFrontend.java:133)
at org.sonar.plugins.java.JavaSensor.execute(JavaSensor.java:109)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:79)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:384)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:380)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:349)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:136)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.ClassNotFoundException: org.junit.rules.TestRule
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 76 more
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
but in custom jar, there is class org/junit/rules/TestRule
[INFO] -----------------< com.nrift.sonar:java-custom-rules >------------------
[INFO] Building SonarQube Java :: Documentation :: Custom Rules 1.0.0-SNAPSHOT
[INFO] ----------------------------[ sonar-plugin ]----------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ java-custom-rules ---
[INFO] com.nrift.sonar:java-custom-rules:sonar-plugin:1.0.0-SNAPSHOT
[INFO] +- org.sonarsource.sonarqube:sonar-plugin-api:jar:8.9.0.43852:provided
[INFO] +- org.sonarsource.java:sonar-java-plugin:sonar-plugin:6.15.1.26025:provided
[INFO] | +- org.sonarsource.java:java-surefire:jar:6.15.1.26025:provided
[INFO] | | \- com.fasterxml.staxmate:staxmate:jar:2.4.0:provided
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:4.2.1:provided
[INFO] | +- org.sonarsource.java:java-frontend:jar:6.15.1.26025:provided
[INFO] | | +- org.sonarsource.java:jdt:jar:shaded:6.15.1.26025:provided
[INFO] | | | \- org.eclipse.jdt:org.eclipse.jdt.core:jar:3.25.0:provided
[INFO] | | | +- org.eclipse.platform:org.eclipse.core.resources:jar:3.16.100:provided (version selected from constraint [3.14.0,4.0.0))
[INFO] | | | +- org.eclipse.platform:org.eclipse.core.runtime:jar:3.24.100:provided (version selected from constraint [3.13.0,4.0.0))
[INFO] | | | | +- org.eclipse.platform:org.eclipse.osgi:jar:3.17.200:provided (version selected from constraint [3.17.0,4.0.0))
[INFO] | | | | +- org.eclipse.platform:org.eclipse.equinox.common:jar:3.16.0:provided (version selected from constraint [3.15.0,))
[INFO] | | | | +- org.eclipse.platform:org.eclipse.core.jobs:jar:3.12.100:provided (version selected from constraint [3.12.0,4.0.0))
[INFO] | | | | +- org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.9.100:provided (version selected from constraint [3.9.0,4.0.0))
[INFO] | | | | \- org.eclipse.platform:org.eclipse.core.contenttype:jar:3.8.100:provided (version selected from constraint [3.8.0,4.0.0))
[INFO] | | | \- org.eclipse.platform:org.eclipse.text:jar:3.12.0:provided (version selected from constraint [3.6.0,4.0.0))
[INFO] | | | \- org.eclipse.platform:org.eclipse.core.commands:jar:3.10.100:provided (version selected from constraint [3.5.0,4.0.0))
[INFO] | | +- org.sonarsource.sslr:sslr-core:jar:1.24.0.633:provided
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.12.0:provided
[INFO] | | \- org.sonarsource.analyzer-commons:sonar-regex-parsing:jar:1.14.1.690:provided
[INFO] | +- org.sonarsource.java:java-symbolic-execution:jar:6.15.1.26025:provided
[INFO] | +- org.sonarsource.java:java-checks:jar:6.15.1.26025:provided
[INFO] | | \- org.sonarsource.analyzer-commons:sonar-analyzer-recognizers:jar:1.14.1.690:provided
[INFO] | +- org.sonarsource.java:external-reports:jar:6.15.1.26025:provided
[INFO] | +- org.sonarsource.java:java-jsp:jar:6.15.1.26025:provided
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-jasper:jar:9.0.33:provided
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.33:provided
[INFO] | | | \- org.apache.tomcat:tomcat-annotations-api:jar:9.0.33:provided
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.33:provided
[INFO] | \- org.sonarsource.analyzer-commons:sonar-xml-parsing:jar:1.14.1.690:provided
[INFO] | \- com.fasterxml.woodstox:woodstox-core:jar:5.2.0:provided
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- xerces:xercesImpl:jar:2.8.1:compile
[INFO] | \- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] +- xalan:serializer:jar:2.7.1:compile
[INFO] +- xalan:xalan:jar:2.7.1:compile
[INFO] +- org.sonarsource.analyzer-commons:sonar-analyzer-commons:jar:1.24.0.965:compile
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.2:compile
[INFO] +- org.sonarsource.java:java-checks-testkit:jar:6.15.1.26025:test
[INFO] | +- com.google.code.gson:gson:jar:2.8.6:provided
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:provided
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.7.0:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.7.0:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | \- org.junit.platform:junit-platform-commons:jar:1.7.0:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.7.0:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.7.0:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.7.0:test
[INFO] +- org.junit.jupiter:junit-jupiter-migrationsupport:jar:5.7.0:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.0:test
**[INFO] +- junit:junit:jar:4.13.2:compile**
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] \- org.assertj:assertj-core:jar:3.19.0:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.166 s
[INFO] Finished at: 2022-05-18T12:28:58+05:30
[INFO] ------------------------------------------------------------------------