Automatically running sonar scan in Maven without specifying sonar:sonar goal

java
maven

(Michael Whidden) #1

Maven 3.0
sonar-maven-plugin 3.6.0.1398

I’d like the sonar:sonar goal to execute automatically during both mvn install and mvn release:perform, but I’m having a hard time figuring out how to do that. Do I need to add ‘phase’ and ‘goal’ tags to my build->plugins->plugin section in the POM?

I tried adding <phase>test</phase> and <goals><goal>sonar</goal></goals> which sort of worked for regular builds, but seriously hosed up builds done with ‘mvn release:perform’. Specifically, I get the error

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (distro-assembly) on project xxxx-dist: Failed to create assembly: Error adding file 'com.xxxx:xxxx:jar:6.1.0.1' to archive: /data/jenkins/jenkinsData/workspace/xxxx/xxxx-6.1.x/xxxx/target/classes isn't a file.


(Tibor Blenessy) #2

hello @mwhidden,

can you share simple project reproducing the issue? we don’t usually do this, because we want to launch analysis explicitly, but it should be doable the way you describe.


(Michael Whidden) #4

I can. How should I deliver it?

I have located the key item in the log where the behavior diverges. With the sonar plugin NOT bound to the test phase, the assembly plugin is gathering all the module jars and their dependencies into a tar.gz.
This is logged and the assembly succeeds.

[INFO] [DEBUG] Adding dependency artifact com.demo:demo-cl:jar:1.0.
[INFO] [DEBUG] Adding artifact: com.demo:demo-cl:jar:1.0 with file: /data/jenkins/jenkinsData/workspace/Demo/demo-cl/target/demo-cl-1.0.jar to assembly location: lib/demo-cl-1.0.jar.
[INFO] [DEBUG] Adding file: /data/jenkins/jenkinsData/workspace/Demo/demo-cl/target/demo-cl-1.0.jar to archive location: lib/demo-cl-1.0.jar

However, if I enable the sonar plugin, the the sonar scan runs during the module build that runs the assembly (because this is the last module of the multi-module build). After the sonar scan runs, the assembly plugin runs, but the output of the assembly differs from the above:

[INFO] [DEBUG] Adding dependency artifact com.demo:demo-cl:jar:1.0.
[INFO] [DEBUG] Adding artifact: com.demo:demo-cl:jar:1.0 with file: /data/jenkins/jenkinsData/workspace/Demo/demo-cl/target/classes to assembly location: lib/demo-cl-1.0.jar.
[INFO] [DEBUG] Adding file: /data/jenkins/jenkinsData/workspace/Demo/demo-cl/target/classes to archive location: lib/demo-cl-1.0.jar

Followed by:

[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (distro-assembly) on project demo-dist: Failed to create assembly: Error adding file 'com.demo:demo-cl:jar:1.0' to archive: /data/jenkins/jenkinsData/workspace/Demo/demo-cl/target/classes isn't a file. -> [Help 1]

Somehow the sonar plugin is messing with something the assembly plugin looks at to know from where to pull the artifacts.


(Tibor Blenessy) #5

Create a project on github or share a zip on some file sharing platform (e.g. dropbox)


(Michael Whidden) #6

mvn -Dresume=false --update-snapshots release:prepare succeeds (at least as far as the attempt to tag the code in the repo after the assembly)

mvn -Dresume=false -Psonar --update-snapshots release:prepare fails during assembly.

Activating the sonar profile enables the plugin.
Maven version is 3.0.5 (also fails under maven 3.0.3)
OS is RHEL 7.4
Oddly, I cannot reproduce the issue on Windows.


(Tibor Blenessy) #7

If you are not able to reproduce the issue on another OS that could point to the maven config of the user. Can you check the difference in your ~/.m2/settings.xml ?


(Michael Whidden) #8

I ran a diff, and the only difference is that on the linux host, the failing release is run with a profile that add -Xdoclint:none to the java command line, and the maven repo login credentials differ (but they are correct and valid in any case).

The JDK on the linux host is Open JDK 1.8.0_161-b13 and on Windows it is JDK (not Open JDK) 1.8.0_161-b12