Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin: 3.2:sonar - sonarqube

Can anyone help me in getting solution for the below error.
Below are the version of the components to configure
SonarQube 5.1.2
Soanr-Runner 2.4
Java 1.7 [ I have to use 1.7 only since my code supports only 1.7]
mavn 3.3.9
sonar-cobertura-plugin-1.6.3
sonar-findbugs-plugin-3.3
cobertura 2.6
Execution command
mvn -fn -e org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar -Dsonar.jdbc.url="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" -Dsonar.host.url=http://localhost:9000 -DskipTests
In Console Window I am getting error
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:
3.2:sonar (default-cli) on project NWT_Core: Execution default-cli of goal org.s
onarsource.scanner.maven:sonar-maven-plugin:3.2:sonar failed: Unable to load the
mojo 'sonar' in the plugin 'org.sonarsource.scanner.maven:sonar-maven-plugin:3.
2' due to an API incompatibility: org.codehaus.plexus.component.repository.excep
tion.ComponentLookupException: org/sonarsource/scanner/maven/SonarQubeMojo : Unsupported major.minor version 52.0

Since the 3.2, the SonarQube maven plugin requires Java 8.
You have to use the 3.0.2 version for Java 7.
You have to explicitely add this statement to your pom :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.2</version>
</plugin>
Because if you do not do so, by default this plugin uses the LATEST version of the plugin (3.2), hence your error.
See http://docs.sonarqube.org/display/HOME/Frequently+Asked+Questions#FrequentlyAskedQuestions-ShouldIlockversionofSonarQubeMavenplugininmypom.xml?

Regardless of what you compile your code with, the SonarQube analysis should be run with a specific Java version.
You simply need to use different JDK versions for the compilation and analysis.
For SonarQube 6.* compatibility], make sure the JAVA_HOME=/path/to/java8
For SonarQube 9.* compatibility], make sure the JAVA_HOME=/path/to/java11

In my case I had a parent pom with
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I've added my own version also within pluginManagement in my child pom but this didn't work I had to add the plugin to the <build><plugins> nodes instead of <build><pluginManagement><plugins>. Only then new newer version had been used.
Maybe this helps someone.

Recently, install Sonorqube.5.12 image in docker and push the project into Sonorqube. Initially we were facing some maven console errors like major.minor version 52.0.
Later, has been fixed by below step's for me.
Add this plugs in maven.
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
Next, Add default DB setup in ~/.m2/settings.xml file
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:h2:tcp://localhost:9092/sonar</sonar.jdbc.url>
<sonar.host.url>http://localhost:9000</sonar.host.url>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.pdf.username>admin</sonar.pdf.username>
<sonar.pdf.password>admin</sonar.pdf.password>
</properties>
</profile>

It worked for me after using Maven->update project , mvn clean install, mvn clean compile

Related

Maven release plugin scmReleaseCommitComment parameter

I am using maven release plugin for automated releases from Jenkins without any Jenkins-plugins. Release commit, tag and development commit are created in Git and released project is deployed to Nexus.
What I try to achieve is to change the release commit message. As of release plugin documentation there is an option scmReleaseCommitComment, which is per default #{prefix} prepare release #{releaseLabel}. Maven command look like following and all variables are non empty values.
mvn -f ${projectpath}pom.xml release:clean release:prepare release:perform -DreleaseVersion=${RELEASE_VERSION} -DdevelopmentVersion=${DEVELOPMENT_VERSION}-SNAPSHOT -Dtag=v${RELEASE_VERSION} -DscmReleaseCommitComment=${RELEASE_COMMENT}
Adding scmReleaseCommitComment does no effect and commits are still done with default message. What am I missing here?
That feature was introduced in version 3.0.0-M1 of the maven-release-plugin. You can set it to the latest version in the <plugins> section of your pom.xml, as in the example bellow:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
[...]
</plugins>
Not that you can set the scmReleaseCommitComment in the command line as you showed in your question, using mvn ... release:perform ...-DscmReleaseCommitComment=${MY_RELEASE_COMMENT}, or you can set it in pom.xml:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<scmReleaseCommitComment>#{prefix} my comment #{releaseLabel}</scmReleaseCommitComment>
</configuration>
</plugin>
[...]
</plugins>

Maven release plugin fails to release version

I have multi module project where in every pom.xml I have same parent pom.xml.
I'm using maven-release-plugin in order to make a tag in svn with following part of pom.xml of parent
<profile>
<id>make-tag</id>
<modules>
<module>../module1</module>
<module>../module2</module>
<module>../module3</module>
<module>../module4</module>
<module>../module5</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<configuration>
<preparationGoals>validate</preparationGoals>
<tagBase>http://<svn_ip>:8080/repos/DMC/<project>/tags</tagBase>
<useEditMode>true</useEditMode>
<autoVersionSubmodules>true</autoVersionSubmodules>
<updateWorkingCopyVersions>false</updateWorkingCopyVersions>
<tagNameFormat>rel-${env.REL_TAG}</tagNameFormat>
<username>${env.SCM_USER}</username>
<password>${env.SCM_PASSWD}</password>
</configuration>
</plugin>
</plugins>
</build>
</profile>
I'm running this maven via Jenkins and job fails every second time. When it fails I got following error:
[INFO] Can't release project due to non released dependencies :
com.group.id:module1:pom:0.0.1-SNAPSHOT
in project 'module1' (com.group.id:module1:jar:0.0.1-SNAPSHOT)
But on second time the job success. What it can be?

Maven jboss plugin error: "no plugin found for prefix jboss-as"

I get the following error when trying to run the jboss-as:deploy goal.
No plugin found for prefix 'jboss-as' in the current project and in
the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]
available from the repositories [local (/home/user/.m2/repository),
central (http://repo.maven.apache.org/maven2)] -> [Help 1]
I tried out everything written here maven-javadoc-plugin and failsafe-maven-plugin missing when build JBoss Seam examples, but no luck. I need to make this plug-in work without having to add anything in the maven settings file (only in pom).
Assuming your build section has something like this in it:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<jbossHome>/usr/jboss-4.2.3.GA</jbossHome>
<serverName>all</serverName>
<fileName>target/my-project.war</fileName>
</configuration>
</plugin>
</plugins>
</build>
Then you should be using jboss:deploy instead of jboss-as:deploy. But if its like:
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.2.Final</version>
</plugin>
</plugins>
</build>
Then you should be using jboss-as:deploy instead of jboss:deploy.
Both worked for me with a fresh install of maven 3.0.4 with a bare pom.
Yes, Welsh is right.
The first one is located here and the second one here.
So, pay attention if you need to use the "jboss-as" goal specifier or the "jboss" goal specifier.

Maven Install: "Annotations are not supported in -source 1.3"

When running mvn install on my project, i see it fail due to the following errors:
C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
My Maven dependency includes jUnit 4.8, however and has no reference to 1.3 anything.
What would cause these errors? Please advise
You need to specify the source version of your maven project through the use of the maven-compiler-plugin. Add the following to your pom build element and set the appropriate java source and target levels.
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-compiler-plugin/
A shorter version:
<project>
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
....
You are most likely using OpenJDK where the source level is 1.3 when not explicitly set - as opposed to Oracle JDK where the source level is 1.5.
Since most modern Java projects target newer code than Java 5 you most likely need to set this anyway.
Also note that if you need a lower target than source (e.g. for compiling with Java 6 but deploying to Java 5) you can do this by using the Eclipse compiler instead of Javac.
Bu default, the maven tries to compile using Java 1.3 version. I hope most of them hit this error because of missing to tell maven that "Hey Maven, Dont use 1.3 and use "whatever_version_I_give"
This can be mentioned in pom.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
In my above example, I have used 1.7. Please replace with whatever version you wish to.
Add this in your pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

mvn clean install using java 1.5 or 1.6

When I do mvn clean install, I get this error:
annotations are not supported in -source 1.3
(try -source 1.5 to enable annotations)
But where do I put this -source 1.5 command? I tried all permutations with mvn clean install and couldn't get it to work. So I tried putting compilation in my pom, like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
But that didn't work either.. What am I missing?
Thanks!
The latest version of the compiler plugin is 2.3.2. This version seems to support 1.6 as both version and target parameter.
Instead of configuring the compiler plugin, which requires supplying a version, you can
set maven.compiler.source and maven.compiler.target properties in your pom.xml:
<project>
....
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>

Resources