Jenkins error: Plugin requires Maven version 2.2.1 - maven

I have a solution in IntelliJ that builds fine on my local.
Extract from the POM:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<dependencies>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
I have installed Jenkins on my local and created a simple Maven project and pointed it to my POM file from within Jenkins.
When I build the solution from Jenkins I get the following error:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error resolving version for 'org.apache.maven.plugins:maven-surefire-plugin': Plugin requires Maven version 2.2.1
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
On Jenkins I have installed:
Maven Integration plugin
2.15.1
Any ideas / advice would be appreciated.

My own silly mistake. Had to specify the Maven and Java JDK under:
Manage Jenkins --> Global Tool Configuration
After this everything worked.

Related

Use JDK11 for specific Maven submodule compilation fails

I have a Maven project with 3 submodules: 2 of them should be compiled with java8 and one of them with java11. My main JAVA_HOME environment variable when running maven is set to the JDK 8 installed in my machine. I want to specify to use the jdk 11 only for the specific submodule that needs it but I can't make it work.
In the POM father I have the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
In the specific subproject that needs jdk 11 I tried to setup things following this documentation http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html so I have
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_11_HOME}/bin/javac</executable>
</configuration>
</plugin>
and the JAVA_11_HOME variable is set in my settings.xml (according to the doc)
When I run the compilation (either of the whole project or of the single java11 submodule) I get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project features-serving: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
features-serving: Compilation failure
If I run with debug and stacktrace enabled I don't get any useful information. Basically I cannot figure out what it is going wrong. Only thing I am sure is that maven is picking up correctly the JDK 11 path from my settings.xml file.

Integrating Spotbugs into Maven Pom - Won't generate a report?

I am in the middle of trying to integrate the Maven Spotbugs plugin into my project's pom.xml file and make it so that it will generate a report in the "Project Reports" section after running the "mvn site" command. I am able to get other reports, such as PMD, CPD, and Xref to generate, but Spotbugs is given me a lot of trouble. The command line states that the report is successfully configuring, but never generating. I have what seems to be all the required dependencies, build, and report configurations. I've tried all kinds of solutions from the Spotbugs github site, the SpotBugs documentations, multiple forums and tutorials, and nothing seems to fix my problem.
Could anybody give me a very detailed step-by-step on how to incorporate the Spotbugs Maven plugin via the pom file? I am very new to Maven and could use some help! If I need to include any files, let me know that as well.
I followed the directions at spotbugs.readthedocs.io. Add this section into project/build/plugins section of pom.xml.
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.3</version>
</dependency>
</dependencies>
</plugin>
Then I ran mvn spotbugs:spotbugs and it generated projectDir/target/spotbugsXml.xml. Then I ran mvn spotbugs:check and it output
[INFO] --- spotbugs-maven-plugin:3.1.3:check (default-cli) # my-project ---
[INFO] BugInstance size is 0
[INFO] Error size is 0
[INFO] No errors/warnings found
[INFO] --------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------
[INFO] Total time: 6.731 s
[INFO] Finished at: 2018-05-25T16:31:35-04:00
[INFO] --------------------------------------------------------------------
Update - I had to add it to the project/reporting/plugins section as well as the build section. Now when I run mvn site it generates a Project Reports section in the target/site/index.html which includes SpotBugs.
<reporting>
<plugins>
<!-- SpotBugs -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
</plugin>
</plugins>
</reporting>
Stumbled over the same problem and the solution of #Mack did not work for me.
The final solution for me was to create the class files first.
So instead of
mvn site
at least a
mvn compile site
is needed to create the report.
Solved - spotbugs was requiring me to include all required configurations before it worked for some reason. I believe it worked after adding the following under the reporting section of the pom:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Default</threshold>
<spotbugsXmlOutput>true</spotbugsXmlOutput>
<spotbugsXmlOutputDirectory>target/site</spotbugsXmlOutputDirectory>
<skipEmptyReport>false</skipEmptyReport>
<encoding>${project.build.sourceEncoding}</encoding>
<includeTests>true</includeTests>
<classFilesDirectory>${project.build.outputDirectory}</classFilesDirectory>
<spotbugs.xmlOutput>true</spotbugs.xmlOutput>
<plugins>
<plugin>
<groupId>jp.skypencil.findbugs.slf4j</groupId>
<artifactId>bug-pattern</artifactId>
<version>1.4.0</version>
</plugin>
</plugins>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>spotbugs</report>
</reports>
</reportSet>
</reportSets>
</plugin>
Late to the party but following worked for me in december 2022:
mvn spotbugs:check

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

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

dependency-check Maven Plugin

I am trying to get the Maven plugin working to get the dependency-check report. My end goal is to come up with a security-report of the security vulnerabilities on my project.
The Maven snippet which I am using is -
<build>
<pluginManagement>
<plugins>
..
..
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>1.4.0</version>
<configuration>
<dataDirectory>/somepath/data</dataDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
For my build I am using '
mvn -B -U clean install site:site
However, I don't see the dependency-checks being triggered.
I also tried
mvn -B -U org.owasp:dependency-check-maven:1.4.0:check -Dformat=XML
No luck either. I get an error -
[ERROR] BUILD ERROR [INFO]
------------------------------------------------------------------------ [INFO] Internal error in the plugin manager executing goal
'org.owasp:dependency-check-maven:1.4.0:check': Unable to find the
mojo 'check' (or one of its required components) in the plugin
'org.owasp:dependency-check-maven' Can not set
org.sonatype.plexus.components.cipher.PlexusCipher field
org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher._cipher
to org.sonatype.plexus.components.cipher.DefaultPlexusCipher
Where am I going wrong? Thanks and apologies if the question is way too basic!
Thanks 'A_Di-Matteo' for your help.
Furthermore, I noticed I was using Maven 2 for this build (don't ask me why was it even an option). When I used Maven 3, this problem disappeared.

Cobertura maven plugin incorrect version

I am using cobertura and when I specify version 2.5 it downloads 1.9. Why?
My pom:
org.codehaus.mojo
cobertura-maven-plugin
2.5.2
za/co/c2d/*/.class
clean
pre-site
clean
instrument
site
instrument
cobertura
<reporting>
<plugins>
<plugin>
<!-- use mvn cobertura:cobertura to generate cobertura reports -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
Output:
[INFO] --- cobertura-maven-plugin:2.5.2:instrument (default-cli) # services ---
Downloading: http://repo1.maven.org/maven2/net/sourceforge/cobertura/cobertura/1.9.4.1/cobertura-1.9.4.1.pom
When I run this it then breaks with
[ERROR] net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " ">" "> ""
As I understand it, this was fixed in version 2.0.2.
Sure you can't you can't specify version inside brackets ... could you explain more about project hierarchy ? and your full pom.xml ?
This is because you are specifying the version of the cobertura-maven-plugin , which is a different jar from cobertura package
The plugin 2.5.2 uses internally cobertura version 1.9.4.1 as stated in http://mojo.codehaus.org/cobertura-maven-plugin/

Resources