Sonar Maven Plugin does not find classes build in Maven Reactor

SonarQube version: 6.7.6
While scanning Eclipse Plugins (built using Maven Tycho), findbugs and PMD complain about missing classes, though these were successfully built as port of a Multi Module Project within Mavn Reactor

I have a large OSGi Project with ~ 100 Bundles/Modules, that builds without any error but fails at the sonar:sonar phases.
Some module complain about missing class (but not all ?!?)

Another OSGi Project with slightly less Bundles (~85) and identical Sonar Settings get processed without any error.

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
...
[INFO] bundle.main                                     [eclipse-plugin]
...
[INFO] bundle2.using.main                              [eclipse-plugin]
...
[INFO] bundle.using.main                               [eclipse-plugin]
...
[INFO] --------------------< bundle.main >--------------------
[INFO] Building bundle.main 20.0.0                              [37/100]
[INFO] ---------------------------[ eclipse-plugin ]---------------------------
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:build-qualifier (default-build-qualifier) @ bundle.main ---
[INFO] The project's OSGi version is 20.0.0
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-id (default-validate-id) @ bundle.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-version (default-validate-version) @ bundle.main ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.1:prepare-agent (default) @ bundle.main ---
[INFO] argLine set to -javaagent:C:\\Workarea\\Development\\mavenrepo\\org\\jacoco\\org.jacoco.agent\\0.8.1\\org.jacoco.agent-0.8.1-runtime.jar=destfile=C:\\Workarea\\gitrepo\\project\\bundle.main\\target\\jacoco.exec,append=true
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ bundle.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle.main\src\main\resources
[INFO] 
[INFO] --- tycho-compiler-plugin:1.0.0:compile (default-compile) @ bundle.main ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ bundle.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle.main\src\test\resources
[INFO] 
[INFO] --- tycho-source-plugin:1.0.0:plugin-source (plugin-source) @ bundle.main ---
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle.main\target\bundle.main-20.0.0-sources.jar
[INFO] 
[INFO] --- target-platform-configuration:1.0.0:target-platform (default-target-platform) @ bundle.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:package-plugin (default-package-plugin) @ bundle.main ---
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle.main\target\bundle.main-20.0.0.jar
[INFO] 
[INFO] --- tycho-p2-plugin:1.0.0:p2-metadata-default (default-p2-metadata-default) @ bundle.main ...

...

[INFO] ----------------< bundle.using.main >-----------------
[INFO] Building bundle.using.main 20.0.0                       [92/100]
[INFO] ---------------------------[ eclipse-plugin ]---------------------------
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:build-qualifier (default-build-qualifier) @ bundle.using.main ---
[INFO] The project's OSGi version is 20.0.0
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-id (default-validate-id) @ bundle.using.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-version (default-validate-version) @ bundle.using.main ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.1:prepare-agent (default) @ bundle.using.main ---
[INFO] argLine set to -javaagent:C:\\Workarea\\Development\\mavenrepo\\org\\jacoco\\org.jacoco.agent\\0.8.1\\org.jacoco.agent-0.8.1-runtime.jar=destfile=C:\\Workarea\\gitrepo\\project\\bundle.using.main\\target\\jacoco.exec,append=true
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ bundle.using.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle.using.main\src\main\resources
[INFO] 
[INFO] --- tycho-compiler-plugin:1.0.0:compile (default-compile) @ bundle.using.main ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ bundle.using.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle.using.main\src\test\resources
[INFO] 
[INFO] --- tycho-source-plugin:1.0.0:plugin-source (plugin-source) @ bundle.using.main ---
[WARNING] bundle localization file C:\Workarea\gitrepo\project\bundle.using.main\plugin.properties not found
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle.using.main\target\bundle.using.main-20.0.0-sources.jar
[INFO] 
[INFO] --- target-platform-configuration:1.0.0:target-platform (default-target-platform) @ bundle.using.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:package-plugin (default-package-plugin) @ bundle.using.main ---
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle.using.main\target\bundle.using.main-20.0.0.jar
[INFO] 
[INFO] --- tycho-p2-plugin:1.0.0:p2-metadata-default (default-p2-metadata-default) @ bundle.using.main ---
...
[INFO] ------------------< bundle2.using.main >------------------
[INFO] Building bundle2.using.main 20.0.0                          [55/100]
[INFO] ---------------------------[ eclipse-plugin ]---------------------------
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:build-qualifier (default-build-qualifier) @ bundle2.using.main ---
[INFO] The project's OSGi version is 20.0.0
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-id (default-validate-id) @ bundle2.using.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:validate-version (default-validate-version) @ bundle2.using.main ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.1:prepare-agent (default) @ bundle2.using.main ---
[INFO] argLine set to -javaagent:C:\\Workarea\\Development\\mavenrepo\\org\\jacoco\\org.jacoco.agent\\0.8.1\\org.jacoco.agent-0.8.1-runtime.jar=destfile=C:\\Workarea\\gitrepo\\project\\bundle2.using.main\\target\\jacoco.exec,append=true
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ bundle2.using.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle2.using.main\src\main\resources
[INFO] 
[INFO] --- tycho-compiler-plugin:1.0.0:compile (default-compile) @ bundle2.using.main ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ bundle2.using.main ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Workarea\gitrepo\project\bundle2.using.main\src\test\resources
[INFO] 
[INFO] --- tycho-source-plugin:1.0.0:plugin-source (plugin-source) @ bundle2.using.main ---
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle2.using.main\target\bundle2.using.main-20.0.0-sources.jar
[INFO] 
[INFO] --- target-platform-configuration:1.0.0:target-platform (default-target-platform) @ bundle2.using.main ---
[INFO] 
[INFO] --- tycho-packaging-plugin:1.0.0:package-plugin (default-package-plugin) @ bundle2.using.main ---
[INFO] Building jar: C:\Workarea\gitrepo\project\bundle2.using.main\target\bundle2.using.main-20.0.0.jar
[INFO] 
[INFO] --- tycho-p2-plugin:1.0.0:p2-metadata-default (default-p2-metadata-default) @ bundle2.using.main ---
[INFO] 


[INFO] -------------  Scan bundle.using.main
[INFO] Base dir: C:\Workarea\gitrepo\project\bundle.using.main
[INFO] Working dir: C:\Workarea\gitrepo\project\bundle.using.main\target\sonar
...
[INFO] Execute PMD 6.9.0
[INFO] Java version: 1.8
[INFO] PMD configuration: C:\Workarea\gitrepo\project\bundle.using.main\target\sonar\pmd.xml
[INFO] Execute PMD 6.9.0 (done) | time=1047ms
[INFO] Sensor PmdSensor [pmd] (done) | time=1060ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=15ms
[INFO] Sensor FindBugs Sensor [findbugs]
[INFO] Loading findbugs plugin: C:\Workarea\gitrepo\project\bundle.using.main\target\sonar\findbugs\findsecbugs-plugin.jar
[INFO] Findbugs output report: C:\Workarea\gitrepo\project\bundle.using.main\target\sonar\findbugs-result.xml
The following classes needed for analysis were missing:
  package.bundle.main.groups.GroupingIdentifierExtractor
  package.bundle.main.identity.ComponentNames
...
[INFO] -------------  Scan bundle2.using.main
[INFO] Base dir: C:\Workarea\gitrepo\project\bundle2.using.main
[INFO] Working dir: C:\Workarea\gitrepo\project\bundle2.using.main\target\sonar
[INFO] Source paths: pom.xml, src
[INFO] Source encoding: UTF-8, default locale: de_CH
...
[INFO] Execute PMD 6.9.0
[INFO] Java version: 1.8
[INFO] PMD configuration: C:\Workarea\gitrepo\project\bundle2.using.main\target\sonar\pmd.xml
Jul 08, 2019 1:15:04 PM net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver getFieldType
WARNUNG: Error during type resolution due to: java.lang.NoClassDefFoundError: bundle/main/model/valuta/ValutaDateModel
[ERROR] Fail to execute PMD. Following file is ignored: bundle2.using.main/src/bundle2/using/main/executor/spi/ExecutorComponent.java
net.sourceforge.pmd.PMDException: Error while processing file:///C:/Workarea/gitrepo/project/bundle2.using.main/src/bundle2/using/main/executor/spi/ExecutorComponent.java
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:102)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51)
	at org.sonar.plugins.pmd.PmdTemplate.process(PmdTemplate.java:101)
	at org.sonar.plugins.pmd.PmdExecutor.executeRules(PmdExecutor.java:131)
	at org.sonar.plugins.pmd.PmdExecutor.executePmd(PmdExecutor.java:98)
	at org.sonar.plugins.pmd.PmdExecutor.execute(PmdExecutor.java:80)
	at org.sonar.plugins.pmd.PmdSensor.execute(PmdSensor.java:71)
...
Caused by: java.lang.TypeNotPresentException: Type bundle.main.model.pricing.PriceModel not present
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
	at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
	at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
	at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
	at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
	at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
	at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90)
	at java.lang.Class.getGenericSuperclass(Class.java:777)
	at net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.getApplicableMethods(MethodTypeResolution.java:481)
	at net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.getApplicableMethods(MethodTypeResolution.java:481)
	at net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver.visit(ClassTypeResolver.java:387)
	at net.sourceforge.pmd.lang.java.ast.ASTName.jjtAccept(ASTName.java:35)
	... 60 common frames omitted
Caused by: java.lang.ClassNotFoundException: bundle.main.model.pricing.PriceModel
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
	... 145 common frames omitted
..
[INFO] Execute PMD 6.9.0 (done) | time=1261ms
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 

[INFO] bundle.main ................................ SUCCESS [  0.523 s]
...
[INFO] bundle2.using.main ......................... SUCCESS [  0.157 s]
...
[INFO] bundle.using.main .......................... SUCCESS [  0.094 s]

INFO] PROJECT 20.0.0 .............................. FAILURE [01:02 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:50 min
[INFO] Finished at: 2019-07-08T13:27:50+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project project.releng.tycho: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar failed: A required class was missing while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar: bundle/main/model/partnerId/PartnerIdAware
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:sonar-maven-plugin:3.6.0.1398
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Workarea/Development/mavenrepo/org/sonarsource/scanner/maven/sonar-maven-plugin/3.6.0.1398/sonar-maven-plugin-3.6.0.1398.jar
[ERROR] urls[1] = file:/C:/Workarea/Development/mavenrepo/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/C:/Workarea/Development/mavenrepo/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/C:/Workarea/Development/mavenrepo/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[4] = file:/C:/Workarea/Development/mavenrepo/org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.jar
[ERROR] urls[5] = file:/C:/Workarea/Development/mavenrepo/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>group:project.releng.tycho:20.0.0, parent: ClassRealm[maven.api, parent: null]]]
[ERROR]

Hi,

This seems that this is an old known problem : https://jira.sonarsource.com/browse/MSONAR-84

And we have struggled to properly get a reproducer for a long time. Would you be able to reduce the problem to a small example so we can try to fix the issue ?

Thanks in advance.

Note one thing : this is a failure happening on the PMD plugin side. I believe it is worth to first report this on their github : https://github.com/jensgerdes/sonar-pmd

I am not sure how they are computing the classpath so I don’t know if the issue would be on sonar-maven scanner side or on our PMD side at this stage.

Hi,
Since I was under pressure to deliver into our SonarQube, I had to fix the prios :wink:
The workaround was to use sonar.inclusion and incrementally add packages until the analysis worked.
I was left with 5 java packages being problematic (out of 70 top level ones)… but these are still about 100 classes.

Reducing the aggregator isn’t feasible :-/ I have a large bunch of basis modules that are absolutely mandatory…
I wanted to drill down one of the faulty package, hoping to point at the “naughty” class…
I’m not so far yet… this take me a lot of time.
No logging /debugging option here ?

Hi (2),
Well I have errors in 2 places

  • findBugs
    Complaining about missing classes (that do actually exist)
  • PMD
    Throwing out huge stacktrace about the same issue…
    BUT not all findBugs missing classes lead to a PMD stacktrace

Classpath ist set using Sonar’s JavaResourceLocator.£
-> I guesst I need to have a look at the source code in https://github.com/SonarSource/sonar-java;-)

hello @Al8X,

you might also consider to run pmd and findbugs separately and import the reports as external issues https://docs.sonarqube.org/latest/analysis/external-issues/

This way you don’t need to have pmd and findbugs plugins in SonarQube and they don’t need to be executed as part of the analysis.