Our project is a multi module plugin project built using maven. The Sonar analysis runs fine but in the process generates a lot of warnings and probably incorrect results. Below is the set up of the project and warnings generated during analysis. Any help in fixing these warnings is highly appreciated.
Project setup:
Sonar analysis via the jenkins build.
Jenkins Sonar plugin is used to run the analysis.
Jenkins and Sonar along with MySQL are running on different machines.
Below properties are provided to Sonar plugin in Jenkins during sonar analysis.
-Dsonar.profile="My Project Profile"
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.core.codeCoveragePlugin=jacoco
-Dsonar.jacoco.reportPath=../../releng/com.mycompany.myproject.releng.builds/coverage_data/jacoco.exec
Below are the warnings generated during analysis:
Note: The below warnings are not generated if Sonar and Jenkins are running in the same machine
Before the Sonar analysis of individual modules the following error is thrown.
[WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
15:04:52 [WARNING] o com.mycompany.myproject.plugins:com.mycompany.myproject.external.libraries:jar:1.0.0-SNAPSHOT (provided)
15:04:52 [WARNING] Try running the build up to the lifecycle phase "package"
15:04:52 [WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
15:04:52 [WARNING] o com.mycompany.myproject.plugins:com.mycompany.myproject.somefunctionality.framework:jar:1.0.0-SNAPSHOT (provided)
During the analysis of the modules, it throws the following warning
Class 'com/mycompany/myproject/core/common/datatransfers/MyClass' is not accessible through the ClassLoader.
[WARN] [15:05:25.731] Class 'com/mycompany/myproject/core/common/datatransfers/MyClass' is not accessible through the ClassLoader.
Almost all modules are marked as skipped after the analysis after the build is complete, However the analysis results are available in Sonar.
[INFO] com.mycompany.myproject.platform.feature ................ SKIPPED
[INFO] com.mycompany.myproject.somefeature.feature ... SKIPPED
[INFO] My Product ............................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
I know this is a late reply, but I had the same problem and it turned out that I had run mvn clean package instead of mvn clean install. I found this thread on the SonarQube mailing list, hope this helps.
This warning may simply due to a race condition in plugins such as maven-jar-plugin (I had the same warning in another Sonar unrelated case with Maven 3.6.3).
Let's consider the following project layout:
acme-parent parent for all project
acme-aggregator
acme-common
acme-p1 depends on acme-common
acme-p2 depends on acme-common
acme-p3 depends on acme-common
acme-p4 depends on acme-p2 and acme-p3
Maven will build in this order:
acme-parent
acme-common
acme-p1, acme-p2, acme-p3 and acme-p4
However, for the internal machinery, it is another story:
acme-p2 and acme-p3 are not in the local repository
all are in the reactor
during invocation of a plugin in acme-p1, maven will validate the artifact found in the reactor and will try to resolve path of local artifact but fail (hence the warning).
If you move acme-p4 before acme-p1, this change the build order: the warning goes away (note: the dependencies needs to be removed from local repository) because now, acme-p2 and acme-p3 are effectively built before acme-p1.
Maven will build in this order:
acme-parent
acme-common
acme-p2, acme-p3, acme-p4 and acme-p1
There are some fixes:
Adding a dependency from acme-p4 to acme-p1: this will enforce the build order at the cost of extra care (in my real use case, acme-p4 packages acme-p2 and acme-p3 using maven-assembly-plugin).
Reorder project in reactor: I did not test that with the -T options, allowing concurrent build, but I think it may also fail.
Do a package build: it is mentioned by the warning, but I suspect that Maven will in some case reference an artifact in the local repository or in the remote repository (if you deploy SNAPSHOT on them). This may be tricky: if someone change the signature of a method, then Maven may download the SNAPSHOT (it is newer, and it is NOT in the reactor, therefore it is better than the local repo) and the build may fail (this is purely my hypothesis).
This may also be an error in Maven in how it order module in the reactor.
Related
I want to release a module via Jenkins that uses a dependency which is not only distinguished by its version but also by a custom classifier passed as a system property at build time. The effective pom printed in the console output shows that the correct classifier is used
<dependency>
<groupId>de.test</groupId>
<artifactId>common-module</artifactId>
<version>0.0.4-SNAPSHOT</version>
<classifier>custom</classifier>
<scope>provided</scope>
</dependency>
However, when the release plugins' prepare goal runs, the build breaks due to a compilation error because of missing classes which are only available in the dependency version that uses the custom classifier. Printing the properties with the maven-antrun-plugin reveals that the release plugin is using the version without classifier.
[INFO] [echoproperties] de.test\:common-module\:jar=/var/lib/****/.m2/repository/de/test/common-module/0.0.4-SNAPSHOT/common-module-0.0.4-SNAPSHOT.jar
[INFO] [echoproperties] maven.dependency.de.test.common-module.jar.path=/var/lib/****/.m2/repository/de/test/common-module/0.0.4-SNAPSHOT/common-module-0.0.4-SNAPSHOT.jar
I would expect the release plugin to pickup the jar named common-module-0.0.4-SNAPSHOT-custom.jar which is definitely available in the maven repository. Doesn't the release plugin support classifiers?
Problem solved. I found out that there are two issues. First, the module was also part of a transitive dependency, so maven tried to download a version without classifier that doesn't exist prior to the version containing the classifier. Second, the classifier was not passed to the maven release plugin. To pass system variables to the plugin one has to use the arguments option, so the actual command should be clean install -Darguments="-Dmy-classifier=custom" -Dmy-classifier=custom -B release:prepare release:perform. The system variable declaration must be redundant, one for the pom dependency and another for the release plugin.
I am doing a Sonar analysis of my project on a Jenkins Server using SonarRunner within an ant build. Unfortunately, the Analysis crashes with the following lines:
[sonar:sonar] 11:29:57.008 INFO - Execute Findbugs 2.0.3...
[sonar:sonar] 11:29:58.217 DEBUG - Release semaphore on project : org.sonar.api.resources.Project#5c1f0a26[id=3998,key=<key>,qualifier=TRK], with key batch-<key-batch>
[sonar:sonar] 11:29:58.247 DEBUG - To prevent a memory leak, the JDBC Driver [com.mysql.jdbc.Driver] has been forcibly deregistered
BUILD FAILED
<Path>: The following error occurred while executing this line:
<Path>: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
I have other projects running on the same server, which have no problem performing this analysis (and where the analysis is triggered exactly the same way). As you can see, I changed the log level to DEBUG, but, nevertheless, I get no stack trace and I am not able to find useful information in the logs of Jenkins or Sonar.
One other thing, I tried, was to increase the Heap space (with -Xmx) for this ant task in Jenkins but that didn't help either.
Are there any other settings I can take to get useful information or does somebody know about this problem?
Thanks!
Some more information could be useful. E.g.: what SonarQube and SonarRunner versions are you running.
Findbugs is one of the few analyzing plugins that need .class data for analyzing the project. So if you have not changed the directory within your build.xml the ant task may search within the default output folder location.
Please make sure your .class files are located here. To make them appear here you have to compile them before of course
I have created maven based web application so after created application i am getting two errors in pom.xml which are
1.Multiple annotations found at this line:
- Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted
until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (http://
repo.maven.apache.org/maven2): null to http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
2.Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile)
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.1
Could you please let me know what needs to be done for resolving the issue
If you are facing the same issue I described in my comment above then it seems I could fix it by running mvn eclipse:eclipse with working directory set to Eclipse project folder i.e.
$ cd /path/to/eclipse/workspace/Project
$ mvn eclipse:eclipse
Does this work for you ? Maybe your environment is different . Providing more details might help others to understand your problem even better so as to offer useful suggestions .
I had similar problem Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile).
To Fix (apart from installing M2E plug-in and all):
Ensure installed maven is > 3.1 (using mvn -v). If not, you need to upgrade.
Ensure eclipse is pointing to correct maven location (Window->Preferences->Maven->Installations)
On Command prompt, go to project home directory and run mvn eclipse:clean and mvn eclipse:eclipse
Disable and enable Maven nature in eclipse (Right click on project, goto Maven -> Disable Maven Nature. To enable, Right click on project goto Configure -> Convert to Maven Project)
Im trying to run a sonar analysis on a Jenkins Job. Im using ant so im using Sonar Runner and sonar.properties in the projects. Im configuring the the binaries to
sonar.binaries=build/ant/classes
After a successfull build Sonar starts and is running a while. But i get a lot of warnings during bytecode analysis.
Im getting WARN XX - Class 'XX' is not accessible through the ClassLoader.
for every class...
I dont really know why classes are all there?
These are warnings issued by Findbugs, which requires access to source, compile binaries and 3rd party libraries.
To resolve these warnings you need to include an additional sonar.libraries property, populated with the 3rd party jars your code depends upon (See Analaysis Parameters documentation)
I actually had the same problem, but that was because of an issue with the maven caches.
I had run mvn clean install in the directory on my local machine, but was running sonar on the directory on a virtual box. This resulted in classes not being found.
Does anybody know of any reason why some of my projects are marked as SKIPPED at the end of a successful maven build?
please note that the 'skip chain' always starts with my web project which includes the following features:
jspc-maven-plugin
war plugin with overlay
maven-dependency-plugin
It could be due to OutOfMemoryError's inside Maven. We had similar problem with Maven skipping half of the modules. Increasing memory for Maven process itself solved the issue. I don't know if it is specific to some particular plugin behaving bad or to the Maven core.