Specifying version of Sonar plugin - maven

I have a Maven multi-module project and as part of my build I execute
mvn sonar:sonar
I get some unexpected behaviour with a particular maven plugin that there is no need to go into here and after a lot of debugging and trial-and-error, I decided to tweak the particular plugin in question to add some debugging. The plugin in question is the sonar javascript plugin (https://github.com/SonarSource/sonar-javascript).
I cloned the git repo, incremented the version to 2.16 (latest available is 2.15), modified a logging statement, executed mvn install. Then I went back to my project hoping that when I executed mvn sonar:sonar it would simply pick up the latest version of this plugin available on my local repo. It didn't. I tried adding this to my pom:
<plugin>
<groupId>org.sonarsource.javascript</groupId>
<artifactId>javascript</artifactId>
<version>2.16</version>
</plugin>
Still nothing. The logging statement is unchanged.
So how can I get the sonar execution to pick up my locally installed version of the plugin?

Just install the plugin on your SonarQube server.
Changing the plugin source means that you'll be on your own from their on though. If you've got legitimate issues/feedback with the JavaScript Plugin, then reach out to their maintainers on the SonarQube Google group. Constructive feedback will be heard, you'll get a chance to contribute directly to the sonar-javascript project, and the community we'll be able to benefit from your improvement(s) (rather than you flying solo with custom changes).

Related

maven-release-plugin - Not found

I am trying to add maven release plugin to pom.xml file but it returns
Plugin 'org.apache.maven.plugins:maven-release-plugin:' not found
What you're seeing is your IDE complaining that it doesn't know (yet) about this new plugin you've added. It looks like Intellij IDEA from Jetbrains, so my first advice would be to:
run a maven goal that includes this plugin; for example mvn release:help. This will make sure the plugin gets resolved and downloaded (it is in central so should give no problems)
you should also see the release plugin be listed in the maven tab in IDEA now under plugins
tell IDEA to update it's own state from maven. IDEA has a hard time detecting new plugins, as they're not part of the normal project build dependencies. See Force Intellij IDEA to reread all maven dependencies
If the maven goal runs fine, the plugin is working. Try refreshing in IDEA or closing + reopening the project a few times until IDEA gets it.
Regarding the "missing" version tag. If you're not specifing an exact version of the plugin to use, you're currently getting this plugin (version) from the maven super pom:
https://maven.apache.org/ref/3.8.5/maven-model-builder/super-pom.html
you can run the following maven command to view your combined effective pom; super pom, your own pom + default bindings: mvn help:effective-pom
your current configuration should be sufficient, but if you want more control you can specify a version explicitly. See the following link for available version: https://search.maven.org/artifact/org.apache.maven.plugins/maven-release-plugin
if you really want this "error" from IDEA to go away, you must specify the version. It seems IDEA doesn't understand that the version is inherited from the super pom. You can tell because the error message org.apache.maven.plugins:maven-release-plugin: is in the format of groupid:artifactid:version, and version is missing. Adding a version would look like something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
(this is the default for maven 3.8.5, you can pick a newer version if you want)

Sonar Maven plugin is failing because of a newer maven assembler plugin, how can I get the new plugin to pass properties correctly?

Had to update our maven assembler version to 1.1.8 from 1.1.6. It's the only change that happened and now Sonar Maven Plugin is throwing this exception:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar
(default) on project ReconCoverage: java.util.ArrayList cannot be cast to java.lang.String ->
Plugins:
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7</version>
<groupId>com.CORPNAME.raptor.build</groupId>
<artifactId>assembler-maven-plugin</artifactId>
<version>1.1.8</version>
I have been looking into this for about a week, upgrading to this assembler version is required. No other teams are experiencing this issue from the upgrade because they are using Sonar through jenkins. I'm using the maven plugin because our project has many modules, and it structures the coverage results to match it.
I have looked through sonar's code and it seems to be happening in sonar.batch.bootstrap.userproperties. I'm guessing this is happening when the sonar properties are being passed in, items like: sonar.language, sonar.java.coveragePlugin, sonar.host.url, etc. etc.
Example of Coverage Properties:
<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.host.url>http://corp.sonar.url/</sonar.host.url>
<sonar.jdbc.url>jdbc:oracle:thin:#sonardb.corp.com:0000:sonardb</sonar.jdbc.url>
<sonar.jdbc.username>username</sonar.jdbc.username>
<sonar.jdbc.password>password</sonar.jdbc.password>
<sonar.jdbc.driver>oracle.jdbc.driver.OracelDriver</sonar.jdbc.driver>
According to sonar's code, it normally takes properties through a Map. And it throws this exception when one of those strings is an array list. Is there anyway to configure my properties so that the new maven assembler will pass these values correctly?
We have implemented a workaround in version 3.1.1 to circumvent buggy plugins injecting non string properties:
https://jira.sonarsource.com/browse/MSONAR-145
To use it just update you pom.xml to use:
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
I finally found a workaround for this problem. I decided to not go the route of running Java 7 and then 8 to build the coverage report(check previous answers and comments). I'm sure that would work, but since none of our dev or CI machines had Java 8 environments set up, I tried a different route.
I was initially building the sonar report at the end of a mvn clean install through a module CoverageModule(which as the last module to build). The 1.1.8 java assembler version was throwing a fit when it built the project, and then ran the analysis.
I kept the module so that during a normal build, it would still run my ant task plugin to merge all of our module's Jacoco reports. I removed the sonar-maven-plugin from that module's pom and put it in the Project's aggregator module(parent of all modules). After running a full mvn clean install, I can run a mvn sonar:sonar and there appears to be no conflict with the new assembler version, and the old sonar version I was using.

How can I configure Jenkins not to deploy to Maven repository unless I am performing a release build?

I have configured a Jenkins job to build a Maven 3 project and with the "Maven release build" plugin enabled and also added a post-build action to deploy the artifacts to a Nexus repository.
However, I don't want artifacts to be deployed unless the user had initiated the build by clicking the "Perform Maven Release" link instead of the "Build Now" button. When the click "Build Now" I just want a snapshot build that doesn't get deployed anywhere.
I understood from the documentation that I could use a environment variable called IS_M2RELEASEBUILD to control this behavior. This environment variable is set to true by the M2 Release Plugin when the build was initiated via the "Perform Maven release" link. But the post build action is completely ignoring this.
I am using Jenkins LTS 1.509.3 and Maven 3.0.5.
UPDATE: Please note that I am not looking for a workaround using using the Maven Release Plugin within the POM. My goal is to create a single Jenkins job that acts as the CI build (without deploying the snapshot) triggered by check-ins and to be able to use the same job to perform a release build using the Jenkins M2 Release plugin.
Take a look on Flexible Publish Plugin:
I think you can easily check your environment variable against required pattern
and trigger proper post build action (sorry, do not have deploy to maven)
If you add the deploy action to the maven release goals then you don't need a separate step in the Jenkins job. These goals are only executed on release:perform. Something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>
Peter Schuetze answered this in the comments and should probably post this answer to get the bounty.
My Comment to the question is apparently the answer. ;)
can't you add the deploy goal to the release goals? I would guess that
it will then only be executed, if it is an release.

add external plugin to intellij maven project

I'd like to add a plugin to my maven project in Intellij, but I'm not sure where I should download from and where I should put the jar files. For example, I want to use
<plugin>
<groupId>funambol</groupId>
<artifactId>rhinounit-maven-plugin</artifactId>
...
or
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
...
in my pom.xml, but the text between the tags is red.
The rhineunit-maven-plugin does not seem to be found in any central repository. You will have to download the plugin sources yourself from here and then build them by running mvn install where the pom file is located. This will install the plugin in your local repository and the version will be 1.0.
Regarding the jasmin-maven-plugin it can be found here and as you can see the latest stable version is 1.1.0. That means that you will only have to add the version 1.1.0 to your plugin statement and the plugin will be downloaded when you run mvn install (actually in an earlier maven phase but don't bother about that).
Here seems to be a good article on how to use rhinounit-maven-plugin so you should go ahead and study it.
Regarding the tags being red that is caused by IntelliJ not being able to find the jar files in the local repo, especially if you don't set the version for the plugins. Normally IntelliJ shows a little green growl-like thing in the upper right corner that states "Maven projects need to be imported" when you change your pom files from within IntelliJ. If you select "Import Changes" it will try to download your dependencies. Another way to solve it is to run mvn install on your own project from the command line.

Sonar not picking up clover test results created by running maven in jenkins

I've been working on this all day and haven't been able to find a solution, so thought i'd turn to the stackoverflow community.
I have a server setup with Jenkins (version 1.454). It's configured to perform the build with Maven (version 3.0.4). The build command is as follows:
clean clover2:setup verify clover2:aggregate clover2:clover
Jenkins has the sonar plugin installed and configured. My sonar install (version 3) is on a different server to jenkins. After the build is completed, i can see the results on sonar (the basics of the build).
I have installed to sonar the clover plugin (sonar-clover-plugin-2.8.jar) manually by putting it into the 'extentions/plugins' folder. It appeared in sonar and I can configure it. I put in the license, version (3.1.4) and sonar.clover.reportPath as "target\site\clover\clover.xml".
When I run the build, it is successful as before, and I can see the basic results as before in Sonar, however, I cannot see any test code coverage results.
When I look at the maven build output I notice the following:
[INFO] Writing report to '/opt/jenkins/jobs/foo/workspace/target/site/clover/clover.xml'
and then near the bottom of the output:
[INFO] [15:08:36.586] Clover XML report not found
The following are also in my pom:
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.clover.reportPath>target\site\clover\clover.xml</sonar.clover.reportPath>
<sonar.surefire.reportsPath>target\surefire-reports</sonar.surefire.reportsPath>
<sonar.core.codeCoveragePlugin>clover</sonar.core.codeCoveragePlugin>
<sonar.clover.version>${clover.version}</sonar.clover.version>
When I look on the jenkins box, I can see that it has generated the clover.xml file (infact in my fiddling I have the clover plugin working on jenkins, so i can see the results there!).
I'm guessing at this stage that there is some issue with jenkins and sonar being on seperate boxes.
Any help would be appreciated!
Cheers.
After a lot more fiddling around, it appeared that I needed to change the following:
<sonar.clover.reportPath>${project.build.directory}/site/clover/clover.xml</sonar.clover.reportPath>
<sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
A good reference was the following:
all about pom variables

Resources