Cobertura maven plugin incorrect version - maven

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/

Related

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

Jenkins error: Plugin requires Maven version 2.2.1

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.

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

Maven can't compile java 1.8

I'm trying to use maven to build a jar but I keep getting the error
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project Application: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
mvn -v outputs
mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.10.1", arch: "x86_64", family: "mac"
So it looks like its pointing to the 1.6jdk
but I have the 1.8 jdk
java -version
java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.brian.ridecellchallenge</groupId>
<artifactId>Application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
Maven relies on the JAVA_HOME environment variable being set. Set it according to your OS and re-run your build.
Edit:
Use export to set the variable.
export JAVA_HOME=/path/to/java
As a MacOS user, open a Terminal and create or edit a file .bash_profile (in the directory of your user home) and put the following snippet there:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Save that file and reopen a Terminal instance. If you execute export as a command there, you should see a valid JAVA_HOME with the location of your JDK 8 installation. Restart your IDE afterwards and maven should be able to build you nice java target 1.8 code.
Because Maven does not know version of jdk you want to build.
You can try with
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
you can try configuration in compiler plugin. Its working on my local
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<executable><!--path-to-your-java8-home-directoru--></executable>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
I noticed that it seems that maven-compiler-plugin ignores the configurations
<source>1.8</source>
<target>1.8</target>
In fact, building my project with -X maven's option, I see that in the configuration of the maven-compiler-plugin the source and target were forced to be 1.6:
[DEBUG] --------------------------------------------------------------
[DEBUG] Goal: org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile (default-testCompile)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<basedir default-value="${basedir}"/>
<buildDirectory default-value="${project.build.directory}"/>
<classpathElements default-value="${project.testClasspathElements}"/>
<compileSourceRoots default-value="${project.testCompileSourceRoots}"/>
<compilerId default-value="javac">${maven.compiler.compilerId}</compilerId>
<compilerReuseStrategy default-value="${reuseCreated}">${maven.compiler.compilerReuseStrategy} </compilerReuseStrategy>
<compilerVersion>${maven.compiler.compilerVersion}</compilerVersion>
<debug default-value="true">${maven.compiler.debug}</debug>
<debuglevel>${maven.compiler.debuglevel}</debuglevel>
<encoding default-value="${project.build.sourceEncoding}">UTF-8</encoding>
<executable>${maven.compiler.executable}</executable>
<failOnError default-value="true">${maven.compiler.failOnError}</failOnError>
<forceJavacCompilerUse default-value="false">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>
<fork default-value="false">${maven.compiler.fork}</fork>
<generatedTestSourcesDirectory default-value="${project.build.directory}/generated-test-sources/test-annotations"/>
<maxmem>${maven.compiler.maxmem}</maxmem>
<meminitial>${maven.compiler.meminitial}</meminitial>
<mojoExecution default-value="${mojoExecution}"/>
<optimize default-value="false">${maven.compiler.optimize}</optimize>
<outputDirectory default-value="${project.build.testOutputDirectory}"/>
<project default-value="${project}"/>
<session default-value="${session}"/>
<showDeprecation default-value="false">${maven.compiler.showDeprecation}</showDeprecation>
<showWarnings default-value="false">${maven.compiler.showWarnings}</showWarnings>
<skip>${maven.test.skip}</skip>
<skipMultiThreadWarning default-value="false">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>
<source default-value="1.5">1.6</source>
<staleMillis default-value="0">${lastModGranularityMs}</staleMillis>
<target default-value="1.5">1.6</target>
<testSource>${maven.compiler.testSource}</testSource>
<testTarget>${maven.compiler.testTarget}</testTarget>
<useIncrementalCompilation default-value="true">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>
<verbose default-value="false">${maven.compiler.verbose}</verbose>
I solved the problem after much much searches and tries, by forcing the java compiler to use the desired source and target:
<compilerArguments>
<source>1.8</source>
<target>1.8</target>
</compilerArguments>
This adds to the parameters of javac the two parameters above, overwriting the default.
In my case, all works well.
Just a note: I see that with the above configuration, maven calls the javac in this way:
-d [...] -g -nowarn -target 1.6 -source 1.6 -encoding UTF-8 -source 1.8 -target 1.8
The first two "-source" and "-target" parameters are the default parameters that the maven-compiler-plugin uses; the second couple of parameters are the parameters added by the plugin because of the configuration "compilerArguments" described above. It seems that javac just uses the last couple of parameters (if a parameter is repeated more times, the last one overwrites all the previouses), but I'm not sure that this can be considered a standard and "sure" behavior.
I used different versions of maven-compiler-plugin, different version of maven. I checked in deep all my configurations (e.g. system variables, every single script used in execution of java or maven and so on) and I'm sure that all is ok.
It's strange, but my conclusion is that there is a bug in the maven-compiler-plugin with java 8.
I'm not sure but can you try to update your maven.plugin version
try
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<version>3.6.1</version>
</plugin>
If anybody has Eclipse Kepler SR2 and has an issue with Java 1.8 while building project with Maven, try to go to Eclipse Marketplace and search for plugin called Java 8 support for m2e for Eclipse Kepler SR2 this helped me, and now Maven compiles Java 1.8 source without problem.
Yes it seems a bug in the maven-compiler-plugin.When I upgraded from 3.1 to 3.5.1, it works.

Configuring emma with maven to generate xml or text reports

I am trying to add emma to project build. I went through the tutorials here -
Maven emma plugin
But i am not able to figure out how do I specify what kind of reports to generate - i mean txt or xml. How do I add this part to the maven build so that when the POM file builds it generates either txt or xml report in some specific directory.
The functionality has been included in the development version of the Sonatype Emma Plugin, emma-maven-plugin-1.3-SNAPSHOT, but it has not been released yet.
https://github.com/sonatype/emma-maven-plugin/pull/1
and
https://github.com/sonatype/emma-maven-plugin/pull/2
Note that this is not the same as the Codehaus Emma plugin that you referenced in your question, but the change should be minimal.
Once version 1.3 is released, you should be able to put the following in the reporting section of your pom.xml file to get the full range of output formats:
<reporting>
<plugins>
<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<formats>html,xml,txt</formats>
</configuration>
</plugin>
</plugins>
</reporting>
You can use the emma4it-maven-plugin for reporting. The 1.3 version has some issue.
But the 1.4-SNAPSHOT works fine.
Here is the git link for the same : https://github.com/billmag/emma4it-maven-plugin.git
Clone the repo and do a mvn clean install.
Also you can use 1.2 version in case you don't want to use a SNAPSHOT version.
The configuration in pom for reporting is as follows:
<reporting>
<plugins>
<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma4it-maven-plugin</artifactId>
<version>1.4-SNAPSHOT</version>
<configuration>
<verbosity.level>verbose</verbosity.level>
<metadatas>coverage.em path</metadatas>
<instrumentations>coverage.ec path</instrumentations>
<reportDirectory>target/emma/</reportDirectory>
<baseDirectory>${project.basedir}/target</baseDirectory>
<formats>xml,html</formats>
</configuration>
</plugin>
</plugins>
</reporting>
Command to get the reports
mvn org.sonatype.maven.plugin:emma4it-maven-plugin:1.4-SNAPSHOT:report

Resources