Cobertura doesn't work with Java 7 - java

I am using maven 3.0.4, JRE 1.7.0_09.
When I use mvn clean install all my tests passes and everything looks good - here is my surefire plugin configuration:
<plugin>
<version>2.12.4</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- -XX:-UseSplitVerifier is for java 7 -->
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
Now, when I mvn cobertura:cobertura some of my tests have errors like this one:
Expecting a stackmap frame at branch target ....
And some more errors that made me understand that it is not running using JRE7 (for example, Encountered " "|" "| "" at line...)
Here is my cobertura plugin configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
And the reporting is:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
I saw a lot of threads that talk about this issue and the solution is to add this line <argLine>-XX:-UseSplitVerifier</argLine> but it does not help.
What am I doing wrong here?

We are using Cobertura plugin version 2.6 with Java 7 with no problems. This includes some files with Java 7 syntax (multi-catch, e.g.) which used to fail with the earlier plugin version. Nor do I need to use -XX:-UseSplitVerifier in the SureFire plugin any longer.
<properties>
<coberturaMavenPlugin>2.6</coberturaMavenPlugin>
<mavenSurefirePlugin>2.12</mavenSurefirePlugin>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${mavenSurefirePlugin}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${coberturaMavenPlugin}</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
</reporting>

Further to this, the issue we had was to do with Cobertura and the version of Xalan/Xerces.
Looking at http://mojo.codehaus.org/cobertura-maven-plugin/dependencies.html, it can be seen that the cobertura plugin has Transitive Dependencies on Xalan 2.6.0 & Xerces at 2.6.2.
To combat this, I added:
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
<scope>test</scope>
</dependency>
And the tests passed, both during the initial test phase with surefire and the cobertura phase.

Perhaps you can set the compiler source and target version options to version "1.6" Different versions of build tools may choose different defaults for this setting. (Buildr 1.4 defaults to source and target 1.7 these days; Maven 2.x still uses 1.6 or earlier.)

Related

Cobertura on Jenkins Duplicate Test Runs

I have a build that includes cobertura as part of my Jenkins run. However, I realize now that it is running all my tests twice.
I have the project setup as a Maven project in Jenkins. and I had the goal to run set to: clean coberture:cobertura install
I had thought that the install portion of the command would simply run the remaining portions of the install goal, such as package. However, it reruns the compile and all the tests. This is despite the fact that there are already tests there.
I've tried configuring different combinations of pre build and post build steps, but I keep running into issues. In some combinations, the build artifacts, such as jars, never get published on Jenkins. In other cases the test results are missing.
I've thought that perhaps I need to remake the build as just a shell build. I think I could then run the command: mvn clean cobertura:cobertura && mvn install -Dmaven.test.skip=true
I think this would do what I want. It would at least stop running all the tests twice.
Is this the best approach or is there another way?
This is how I am including Cobertura in my POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.foo.bar</groupId>
<artifactId>my-parent</artifactId>
<version>1.2.1</version>
</parent>
<groupId>com.foo.bar.baz</groupId>
<artifactId>osom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<description>TODO</description>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<dependencies>
</dependencies>
<build>
<!-- To define the plugin version in your parent POM -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<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-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<useUnlimitedThreads>true</useUnlimitedThreads>
<parallel>suites</parallel>
<reuseForks>false</reuseForks>
<includes>
<include>**/*Test.java</include>
<include>**/Test*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<!-- use mvn cobertura:cobertura to generate cobertura reports -->
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<aggregate>true</aggregate>
<format>xml</format>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
The best approach I could come up with is to use a "Freestyle" project in Jenkins.
I made the project run two separate maven commands. mvn clean cobertura:cobertura and mvn install -Dmaven.test.skip=true
This prevents the tests from running twice.
If you dont want to run your tests twice, use qualinsight-mojo-cobertura maven plugin instead of cobertura-maven-plugin.

How to specify pluginList as maven dependencies for findbugs-maven-plugin

I would like to know if there is a way to specify findbugs attribute for plugins, pluginList as maven dependencies instead as a file path.
I mean, if I use this configuration:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<configuration>
<xmlOutput>true</xmlOutput>
<xmlOutputDirectory>target/site</xmlOutputDirectory>
<pluginList>/my/path/fb-contrib-6.2.3.jar</pluginList>
</configuration>
</plugin>
</plugins>
</reporting>
Findbugs load the plugins jar and analyze the code as I want. But as you can see, jar location is a fixed path. I would like to use something like this:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<configuration>
<xmlOutput>true</xmlOutput>
<xmlOutputDirectory>target/site</xmlOutputDirectory>
<pluginList>
<dependency>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>6.2.3</version>
</dependency>
</pluginList>
</configuration>
</plugin>
</plugins>
</reporting>
Obviously, the last configuration does not work, but it is more convenient from a Maven point of view.
Yes you can do it with the <plugins> parameter, and not <pluginList>.
Quoting the documentation:
The pluginList option specifies a comma-separated list of optional BugDetector Jar files to add.
...
The plugins option defines a collection of PluginArtifact to work on.
A sample configuration would be:
<configuration>
<plugins>
<plugin>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>6.2.3</version>
</plugin>
</plugins>
</configuration>

Why to specify java version in maven build?

When I was building my project like :-
mvn clean install -DskipTests
, then it was giving some error.
After that, I just added, -Djdk.version=1.8, then it works fine.
Can someone tell what is the reason for this?
Try something like this in your pom:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
</build>
It may be because you might be missing the maven-compiler-plugin.
Try the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
</build>
From Maven 3, it defaults to JDK 1.5. So if you do not include the version, it will take JDK 1.5 as default compiler version.
Since, you mentioned that you used JDK 1.8, and the error disappeared. So if you had maven-compiler-version defined in the pom.xml, the error might be because the version would had not been defined.
So by default, it pointed to JDK 1.5 and it was trying to compile the code which would be defined for JDK 1.8 and not for JDK 1.5.
So, it is better to define the correct java version in the pom.xml
Why to specify java version in maven build?
Because Maven won't try to guess the Java version your project was created with (the one you probably only configured in your IDE).
You need to specify the earliest version supported in your pom.xml with:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Getting Maven site plugin working when in profile of multi-module project?

I am attempting to build a full site for my multi-module project in one command that I can execute in Jenkins. However when I build it, the submodule javadocs appear in the site root (site/apidocs instead of site/submodule/apidocs). All the links from the parent to submodule are broken as well.
Organization is the standard
pom.xml
submodule/pom.xml
Parent POM contains:
<build>
<pluginManagement>
<plugins>
... Various unrelated plugins ...
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>complete-build</id>
<build>
<plugins>
<!--JavaDoc setup for Jars-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultAuthor>Leon Blakey</defaultAuthor>
<defaultVersion>${project.version}</defaultVersion>
<sourcepath>target/delombok</sourcepath>
</configuration>
</plugin>
<!--Deploy site with Mercurial (Hg)-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency><!-- add support for scm -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-scm</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-hg</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<configuration>
<reportPlugins>
<!--JavaDoc setup for Site-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultAuthor>Leon Blakey</defaultAuthor>
<defaultVersion>${project.version}</defaultVersion>
<sourcepath>target/delombok</sourcepath>
<show>public</show>
</configuration>
</plugin>
... Checkstyle, PMD, Findbugs, etc ...
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The submodule POM just contains the skeleton plugin definitions for pluginManagement.
When I try to build a site (both on my local machine and Jenkins) I run from the parent
mvn clean install site-deploy -Pcomplete-build
With the above setup, what would cause a submodule to dump its site files in the site root (site/) instead of the submodule directory (site/submodule)? Do I need to use the stanging commands (which I'm avoiding since it breaks the release process)? Is it simply impossible to build a multi-module site in one command?
Use the maven-reactor-plugin to trigger building at the submodule level.

maven: (use -source 5 or higher to enable static import declarations)

How can I use source 5?
I tried
mvn -source 5 test
but it didn't work :-)
When I compile the file by javac, everything works.
You need to configure the maven-compiler-plugin:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
...
</plugins>
...
</build>
</project>
EDIT: Changed example to use latest version of the plugin.

Categories

Resources