Cobertura Checks Fail on Travis CI - java

In my Maven build, I use Cobertura to check that there is a certain minimal coverage:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<check>
<branchRate>100</branchRate>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
When running mvn install, this works fine. However, in Travis CI, the build fails because Travis first runs mvn install -DskipTests=true to get the dependencies. Obviously, when tests are skipped, there is no coverage, and therefore the whole build fails:
[ERROR] ch.trick17.betterchecks.fluent.StringCheck failed check. Branch coverage rate of 0.0% is below 100.0%
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.5.2:check (default) on project better-checks-core: Coverage check failed. See messages above. -> [Help 1]
Can I somehow configure Cobertura to skip the check if tests are skipped? Or is there any other solution, maybe on the Travis side?
Here is my .travis.yml file:
language: java
jdk:
- openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8
script: "mvn install"

You can turn that of by using: install: true which skips the install step.

As an alternative to kmarbaise's answer, instead of completely turning off the install step, you can replace customize it so that it skips the Cobertura check:
install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dcobertura.skip=true -B -V
This way, the output of your actual build script will not be cluttered with output from downloading the dependencies and Maven plugins.

Related

Custom maven plugin: install and execute the plugin in one build

I wrote a custom maven plugin that scaffolds java-code from a custom schema.
The project-structure is like this:
Project
+ plugin
+ web-application
The reactor compiles first the plugin, then the application.
The usual mvn-command is:
mvn
... who is triggering the <defaultGoal>plugin:scaffold package</defaultGoal>
On fresh machines the build fails because the plugin is not yet known at the time the reactor plan the build-phases. So I have to call mvn install first. Then mvn plugin:scaffold package works like a charm.
The problem is: Whenever I modify the scaffolder-plugin and call mvn plugin:scaffold package the modifications of the scaffolder-plugin is not yet used because it is not yet installed into the repository. So I have to call mvn install first again.
Is there a way to:
Install the modification to the plugin
Build the webapplication using the modifications of the plugin
in one step?
First your plugin must be a module of the root project for the resolution to work correctly:
<modules>
<module>plugin</module>
<module>app</module>
</modules>
Then declare the plugin in the build/plugins section your application pom
<build>
<plugins>
<plugin>
<groupId>org.example.plugin</groupId>
<artifactId>plugin</artifactId>
<version>${project.parent.version}</version>
<executions>
<execution>
<id>sayhi</id>
<phase>generate-sources</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The first time you run the plugin or when the plugin changes you need to run at least the package phase so the plugin jar is created. It must be run from the root project:
mvn package
The plugin will be executed during the generate-sources phase:
[INFO] --- plugin:1.0-SNAPSHOT:sayhi (sayhi) # app ---
[INFO] Hello, world.
[INFO]
When you change the plugin just run (again from root project):
mvn package
and you will see the changes:
[INFO] --- plugin:1.0-SNAPSHOT:sayhi (sayhi) # app ---
[INFO] Hello, worldxxxx.
[INFO]
See a full example on Github

How to fix PluginincompatibleException?

I am trying to build a project in Netbeans from Maven Central. When I first tried to build the project there were a number of error messages because plugins didn't have versions specified in the POM. I fixed those problems.
I am running the latest version of Maven 3.5.0. I specified in the POM the latest version of the plugin. Here is the related section of the POM complete with the version number I added.
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<excludeProperties>
<excludeProperty>git.build.*</excludeProperty>
<excludeProperty>git.commit.user.email</excludeProperty>
<excludeProperty>git.commit.message.*</excludeProperty>
<excludeProperty>git.commit.id.describe</excludeProperty>
<excludeProperty>git.commit.user.name</excludeProperty>
<excludeProperty>git.remote.origin.url</excludeProperty>
<excludeProperty>git.commit.id.abbrev</excludeProperty>
<excludeProperty>git.closest.tag.name</excludeProperty>
<excludeProperty>git.closest.tag.commit.count</excludeProperty>
<excludeProperty>git.remote.origin.url</excludeProperty>
</excludeProperties>
</configuration>
</plugin>
I now get the follow fatal error:
cd D:\darren\My Documents\NetBeansProjects\XBee-API; "JAVA_HOME=D:\\Program Files\\Java\\jdk1.8.0_121" cmd /c "\"\"D:\\Program Files\\Java\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dmaven.ext.class.path=\"D:\\Program Files\\Java\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 install\""
Scanning for projects...
Inspecting build with total of 1 modules...
Installing Nexus Staging features:
... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
------------------------------------------------------------------------
Building com.rapplogic:xbee-api 0.9.2
------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/pl/project13/maven/git-commit-id-plugin/2.2.2/git-commit-id-plugin-2.2.2.pom
log4j:WARN No appenders could be found for logger (org.apache.maven.wagon.providers.http.httpclient.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Downloaded: http://repo.maven.apache.org/maven2/pl/project13/maven/git-commit-id-plugin/2.2.2/git-commit-id-plugin-2.2.2.pom (13 KB at 25.6 KB/sec)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.729s
Finished at: Tue Jul 04 22:15:49 NZST 2017
Final Memory: 14M/245M
------------------------------------------------------------------------
Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.2.2:revision (get-the-git-infos) on project xbee-api: The plugin pl.project13.maven:git-commit-id-plugin:2.2.2 requires Maven version [3.1.1,) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginIncompatibleException
The Wiki help page is no help. There is no obvious way to resolve this problem and clear the error.

Maven add javadoc

I'm working in a Maven multimodule project and I'm not able to download javadocs for some dependencies. I'll describe my failed attempts:
I'm working with Netbeans so the first option was Right click in Dependencies -> Download Javadocs and some javadocs were dowoloaded but some other not.
Next option was to use mvn eclipse:eclipse but the result was the same (some javadocs were still missing). Also I saw that mvn eclipse plugin is deprecated
Last option was to use mvn dependency:resolve -Dclassifier=javadoc but the result is the same
I configured the maven-javadoc-plugin in my pom.xml but nothing happens. The configuration is the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
I don't want to use this option because implies a manual downloading. The third option gave me the following output:
[INFO] The following files have NOT been resolved:
[INFO] dom4j:dom4j:jar:javadoc:1.6.1:test
[INFO] org.jboss:jandex:jar:javadoc:1.1.0.Final:test
[INFO] org.hibernate:hibernate-entitymanager:jar:javadoc:4.3.1.Final:test
[INFO] org.hibernate:hibernate-validator:jar:javadoc:5.2.4.Final:provided
[INFO] xml-apis:xml-apis:jar:javadoc:1.0.b2:test
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:javadoc:4.0.4.Final:test
[INFO] org.hibernate:hibernate-core:jar:javadoc:4.3.1.Final:test
[INFO] antlr:antlr:jar:javadoc:2.7.7:test
[INFO] javax.activation:activation:jar:javadoc:1.1:provided
Any help is appreciated, also if someone tells me that there's no other option but to install the artifacts manually.
Thanks in advance.

Maven install passes but there are tests failing

I am running a maven install for a spring boot project with multiple modules in STS.
I can see that there are few test cases failing but the maven install passes and shows build successful.
The tests are not being skipped, they are running during the install stage and the surefire reports are also being generated with failed tests but somehow the build passes.
I want the build to fail as the tests are failing, any pointers are appreciated?
<properties>
<maven-surefire-plugin-version>2.16</maven-surefire-plugin-version>
<junit.version>4.12</junit.version>
...
...
</properties>
..
..
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
...
...
</dependency>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugins>
...
...
...
</pluginManagement>
</build>
Maven logs:
Results :
Failed tests:
MyClassTest.testMyClass:35 null
Tests in error:
MyClass1Test.testMyClass:64 ยป NullPointer
Tests run: 3, Failures: 1, Errors: 1, Skipped: 0
[ERROR] There are test failures.
Please refer to /Users/XXX/yyyy/zzzz/target/surefire-reports for the individual test results.
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) # zzzzz ---
[INFO] Packaging webapp
[INFO] Assembling webapp [zzzzz] in [/Users/XXXX/yyyyy/zzzz/target/zzzz-1.0.0]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/XXXX/zzzz/zzzz/src/main/webapp]
[INFO] Webapp assembled in [232 msecs]
[INFO] Building war: /Users/XXX/yyyyy/zzzzz/target/zzzzz-1.0.0.war
At last, it just shows all the modules build successfully. Shouldn't it stop building the war itself as soon as it detects a failure?
The test phase in the build lifecycle is executed by the Surefire plugin. One of its options, testFailureIgnore, is used to execute tests and sucessfully finish the build regardless of the result. This is useful eg when generating metrics to Sonar.
One way to activate such option is using -Dmaven.test.failure.ignore, perhaps you have enabled such option on your build.
According to documentation of surefire-maven-plugin, it does not fail on test failures by design. The reason is: surefire-maven-plugin should execute all tests and present the general statistics.
If you would like to save time, you can use this parameter:
<skipAfterFailureCount>N</skipAfterFailureCount>
where you stop executing tests after N of them failed.
maven-surefire-report-plugin can be used for reports analysis:
https://maven.apache.org/surefire/maven-surefire-report-plugin/
Any chance the failing tests are run using the failsafe plugin? This plugin does not fail the build on failing tests, as documented on their site:
If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly.
The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.

Adding Grails command to Maven phases -- what am I doing wrong?

I need to build my Grails project with Maven, and it is necessary to add an additional grails command. I'm using the grails-maven-plugin to create the pom file, and I can build the war file with $ mvn package
While building this application, I will need to execute another grails command, one the does not correspond directly to any of the maven build phases. Referring to the docs, I'm adding a second execution element to the grails-maven plugin, as follows:
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
</goals>
</execution>
<execution>
<id>stats</id>
<phase>init</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<command>stats</command>
</configuration>
</execution>
</executions>
</plugin>
For this example I'm trying to execute grails stats in the maven init phase. (Eventually, stats will be replaced by something more useful.) when I run:
$ mvn package
the ouput includes:
[INFO] [grails:validate {execution: default}]
[INFO] [grails:init {execution: default}]
[INFO] [grails:config-directories {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
which evidently doesn't contain the execution of grails stats. I am able to execute the stats command through Maven directly, in the following way:
$ mvn grails:exec -Dcommand=stats
it only fails to execute when added as a goal in the pom.
I'm using Java 1.5.0_22, Grails 1.3.7, and Maven 2.2.1.
Based on the information I could find about this plugin, you should add the grails: prefix to your goals.
I have no experience with this plugin, so I could be wrong =)
References:
http://grails.1312388.n4.nabble.com/grails-maven-plugin-version-td2284532.html
http://www.grails.org/Maven+Integration
so for example: <goal>grails:init</goal>
OK, my problem was confusing goals and Maven phases. Notice I was trying
<phase>init</phase>
and I had tried other items from the list of goals, but these are not Maven phases.
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Categories

Resources