Spring boot and maven build number plugin - maven

I am using Spring boot 2.0.5,and added code to generate build number using maven build number plugin. The build number is generating fine. I can see on jar and in the builNumber.properties file but its not being substituted in finalName in version.txt file.
Additional details:
Here is my POM.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>buildNumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
</build>
I have created version.txt file in resources folder and it has following text.
#project.build.finalName#
On maven clean install this file is updated in target folder. In below logs line # 2 you can see build number is added to jar file name.
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) # try ---
[INFO] Building jar: /home/ubuntu/Spring/SpringBootData-REST/target/try-0.0.1-SNAPSHOT.10.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.5.RELEASE:repackage (default) # try ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # try ---
[INFO] Installing /home/ubuntu/Spring/SpringBootData-REST/target/try-0.0.1-SNAPSHOT.10.jar to /home/ubuntu/.m2/repository/com/try/0.0.1-SNAPSHOT/try-0.0.1-SNAPSHOT.jar
[INFO] Installing /home/ubuntu/Spring/SpringBootData-REST/pom.xml to /home/ubuntu/.m2/repository/com/try/0.0.1-SNAPSHOT/try-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
But buildNumber is not replaced in version.txt.
Here is how it looks after maven clean install.
try-0.0.1-SNAPSHOT.${buildNumber}
Here is buildNumber.properties file with the buildNumber.
#maven.buildNumber.plugin properties file
#Sat Mar 09 11:51:51 CST 2019
buildNumber=10
Can you point out whats wrong?

So I found a workaround.
Changed my Version.txt to below instead of #project.build.finalName# and its working fine now.
#project.artifactId#
#project.version#
#buildNumber#
Output
SpringBootDataRest
1.0
15

Related

How to use maven with Java9.0.1 and pom packaging in Eclipse Oxygen 1a Release (4.7.1a)?

The maven project example that is given below shows an error in module-info.java in Eclipse Oxygen:
log4j.api cannot be resolved to a module.
If I remove the line
<packaging>pom<packaging>
from pom.xml the error disappears. However, I need to use pom packaging. If I use Java8 without module definitions, the maven part in my real world example works very well. Trying to migrate to Java9 confronted me with this new issue. First I thought I would not correctly reference the log4j dependency. Then I found out that is has something to do with the pom packaging that I need in my multi-module project. I created a minimal example that is given below to allow you to reproduce the error messages in Eclipse.
=>Is this a bug of the M2E plugin (1.8.2.20171007-0217)?
=>If not, how do I have to adapt my pom.xml file to work with Java9?
Related issues:
How to use log4j with maven and java9?
Import of a Java-9-Jigsaw-Maven-Project in Eclipse Oxygen 4.7 does not work
Java 9 Modules and JUnit 4
Can Maven generate the module declaration
Where should I put unit tests when migrating a Java 8 project to Jigsaw
Which module should I require in Java 9 to use JPA?
List of java modules: http://download.java.net/java/jigsaw/docs/api/overview-summary.html
Min example project (my real example is more complex):
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>Log4JWithJava9</groupId>
<artifactId>Log4JWithJava9</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<!-- encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- plugin for resource phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>resource-execution</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- plugin for compile phase (and test-compile phase) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<!-- specify current java version here: -->
<source>9</source>
<target>9</target>
</configuration>
<executions>
<execution>
<id>compile-execution</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-execution</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ### PACKAGE ### phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>package-execution</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
<!-- plugin for install phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-execution</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</project>
module-info.java
module Log4JWithJava9 {
exports isi.share;
requires javafx.base;
requires log4j.api;
}
Main.java
package isi.share;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main {
private static Logger sysLog = LogManager.getLogger(Main.class);
public static void main(String[] args) {
}
}
Output for maven run configuration with clean install:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Log4JWithJava9 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Log4JWithJava9 ---
[INFO] Deleting D:\EclipseJava\workspace\Log4JWithJava9\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (resource-execution) # Log4JWithJava9 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\EclipseJava\workspace\Log4JWithJava9\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (compile-execution) # Log4JWithJava9 ---
[WARNING] ********************************************************************************************************************
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
[WARNING] ********************************************************************************************************************
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to D:\EclipseJava\workspace\Log4JWithJava9\target\classes
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (test-compile-execution) # Log4JWithJava9 ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (package-execution) # Log4JWithJava9 ---
[INFO] Building jar: D:\EclipseJava\workspace\Log4JWithJava9\target\Log4JWithJava9-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # Log4JWithJava9 ---
[INFO] Installing D:\EclipseJava\workspace\Log4JWithJava9\pom.xml to C:\Users\eis\.m2\repository\Log4JWithJava9\Log4JWithJava9\0.0.1-SNAPSHOT\Log4JWithJava9-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (install-execution) # Log4JWithJava9 ---
[INFO] Installing D:\EclipseJava\workspace\Log4JWithJava9\pom.xml to C:\Users\eis\.m2\repository\Log4JWithJava9\Log4JWithJava9\0.0.1-SNAPSHOT\Log4JWithJava9-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.520 s
[INFO] Finished at: 2017-11-10T20:41:10+01:00
[INFO] Final Memory: 15M/52M
[INFO] ------------------------------------------------------------------------
Whole Eclipse example project:
https://github.com/stefaneidelloth/java9MavenEclipse
Tools used:
Eclipse for RCP and RAP Developers, Oxygen 1a Release (4.7.1a)
(Including M2E version 1.8.2.20171007-0217)
Java JDK version 9.0.1

maven-compiler-plugin: change <outputDirectory> per execution

situation
I have XML files which I need to deal with in my GUI (JavaXF) and in my JavaStoredProcedures in my oracle12c database.
In the GUI I want to use properties bindings.
So I configured the maven-jaxb2-plugin to generate the sources with properties.
The database on the other hand does not support Java8 therefore is configured a second execution for the maven-jaxb2-plugin to generate the sources without properties in a different folder ending up with two folders containing the same Java-classes in the same packages in different folders.
So what I have now looks like this:
project
\-target
\-generated-sources
+-java7
| \-package.with.java.files
| \-Java7-compilabe-sources*
\-java8
\-package.with.java.files
\-Java8-compilabe-sources*
What I want to do next is to compile the two folders target/generated-sources/java7 and target/generated-sources/java8 to different output folders target/java7/classes and target/java8/classes respectively within different executions of the maven-compiler-plugin.
But I'm not able to change the output directory of the maven-compiler-plugin for a single execution.
This is my current configuration of the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>ISO-8859-1</encoding>
</configuration>
<executions>
<execution>
<id>java8</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<executable>${jdk-1.8}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
<sourceDirectory>${project.build.directory}/generated-sources/java8</sourceDirectory>
<outputDirectory>${basedir}/target/java8/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But from the maven output it looks like it does not respect either one of <sourceDirectory> nor <outputDirectory>:
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 6.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # MyProject ---
[INFO] Deleting /ProjectRoot/target
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java8) # MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java8\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java7) # MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java7\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # MyProject ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # MyProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 114 source files to /ProjectRoot/target\classes
findings
the compiler pluging does not show the execution ID (as the maven-jaxb2-plugin does)
the compiler pluging compiles both target/generated-sources/java7 and target/generated-sources/java8 (each contains 57 *.java files) although <sourceDirectory> is given in execution/config
the compiler pluging compiles to target/classes although <outputDirectory> is given in execution/config
question
how do I force maven to compile each of target/generated-sources/java7 and target/generated-sources/java8 to its own target folder separately?
additional info
$ mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
I solved the problem by usting the maven-antrun-plugin.
first I turend off compilation by excluding all files:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>ISO-8859-1</encoding>
<source>1.8</source>
<target>1.8</target>
<executable>${jdk-1.8}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
I also turned of the maven-jar-plugin
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>never</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
then I configured separate executions in the maven-antrun-plugin to compile eache source folder and create the separate jars.
what's left is to configure the maven-deploy-plugin so that the two jars (and their source jars) are correctly placed in the maven repository so that they can be fetched as dependencies.

How to echo in Maven without Antrun plugin?

How can I print to the console while executing a mvn command (in a phase/goal), but not using Maven Antrun plugin?
Why I reject Antrun solutions:
The overhead in code to print a single message is massiv.
The output is no formated like maven output
I cannot attach a severity to the message (e.g. DEBUG, INFO, ERROR, etc)
Currently an Ant-echo looks like this (see line with "hello world"):
[INFO] --- maven-antrun-plugin:1.7:run (default) # ejpd-alertmanager-ear ---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
main:
[echo] hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
However, I expect it to look like this (see line with "hello world").
[INFO] --- maven-antrun-plugin:1.7:run (default) # ejpd-alertmanager-ear ---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
[INFO] hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I'm positive, I am missing something here, since I cannot be the first to raise this demand. Thank you for any smart hint.
You should try the Maven Echo plugin:
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>This is the Text which will be printed out.</echo>
</echos>
</configuration>
</plugin>
Or furthermore take a deeper look into the integration test of the plugin.
which is available via Maven Central. BTW: If you have further requests/improvements just file in an issue.
You can use Björn Ekryd's Echo Maven Plugin, which is published in Maven Central.
It has a normal amount of XML required for a Maven plugin, the output is formatted like the other Maven log lines, and you can assign a severity level to your message (default is INFO).
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message>war has changed</message>
<level>INFO</level>
</configuration>
</execution>
</executions>
</plugin>
[INFO] --- maven-war-plugin:2.4:war (default-war) # mymodule ---
[INFO] Packaging webapp
[INFO] Processing war project
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (default) # mymodule ---
[INFO] war has changed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Also, this plugin has 95% code coverage, which is pretty cool.
You can use Groovy Maven Plugin for this.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
log.info('Test message: {}', 'Hello, World!')
</source>
</configuration>
</execution>
</executions>
</plugin>
The configuration above will produce the following output:
[INFO] Test message: Hello, World!
I haven't tried this myself but there is a plugin here which may help:
http://code.google.com/p/maven-echo-plugin/

Jenkins + selenium tests with failsafe plugin

I have a Jenkins platform which calls maven to make unit tests (with surefire plugin) and integration tests (with failsafe plugin). When there is an error in the integration tests, Jenkins considers the build as successfull. Is this behavior normal? I'd prefer it considers the build as unstable. More generally, do you know how Jenkins read and interprets the result of the build to consider a build as successfull or unstable? I read somewhere on the net that the failsafe reports must be redirected to the surefire report path. I did id but the problem is still here.
pom.xml :
[...]
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<disableXmlReport>false</disableXmlReport>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<configuration>
<includes>
<include>**/tests/**</include>
</includes>
<excludes>
<exclude>**/testsIntegration/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<disableXmlReport>false</disableXmlReport>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
<includes>
<include>com/acelys/conventionsJuridiques/*.java</include>
<!-- ... inclure les tests Selenium -->
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/testsIntegration/**</include>
</includes>
<excludes>
<exclude>**/tests/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
[...]
output of jenkins :
[...]
mojoStarted org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
[INFO]
[INFO] --- maven-failsafe-plugin:2.7.2:integration-test (integration-test) # BaseContrats ---
[INFO] Failsafe report directory: C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 23.971 sec <<< FAILURE!
Results :
Failed tests:
testHomePage(com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
mojoSucceeded org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
mojoStarted org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
[INFO]
[INFO] --- tomcat6-maven-plugin:2.1-SNAPSHOT:shutdown (tomcat-shutdown) # BaseContrats ---
25 févr. 2013 09:32:08 org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
25 févr. 2013 09:32:08 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
25 févr. 2013 09:32:08 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
mojoSucceeded org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
projectSucceeded BaseContrats:BaseContrats:1.0-SNAPSHOT
sessionEnded
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:07.408s
[INFO] Finished at: Mon Feb 25 09:32:08 CET 2013
[INFO] Final Memory: 13M/51M
[INFO] ------------------------------------------------------------------------
Projects to build: [MavenProject: BaseContrats:BaseContrats:1.0-SNAPSHOT # C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml]
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.pom
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\ConventionsJuridiques.war to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.war
channel stopped
Finished: SUCCESS
According to the documentation:
failsafe:verify verifies that the integration tests of an application passed.
You need to add the goal to the maven-failsafe-plugin execution:
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
This will allow Jenkins to interpret the test results and mark the build as unstable.
You can see that maven finished with SUCCESS. This will have Jenkins also finish with success.
To mark build as unstable, you need a post build action that will analyse your test results and mark build as failed or unstable. I suggest you search for more details on Jenkins post build actions for processing the test results and marking build as needed.
Hope this helps.
Under the post build actions the Publish JUnit test result report changes the report XML's to search for.
The assumption is the standard surefire and failsafe plugin output directories are used.
changes to
You should add a step in your build : "publish Junit report"
You will have graph showing all your test result, but it will also set the correct build result if tests are failing.
As said by https://stackoverflow.com/users/709863/stephane-piette:
Add a post build action 'Publish Performance test result report'. This action is provided by the plugin named 'Performance plugin'. You probably do not have this plugin installed, which is why it does not exist in the list.
The goal "integration-test" of the failsafe plugin won't mark the build as error when tests fail.
You have to add the goal "verify" to run after "integration-test" in the plugin execution. This will look for errors or failures and mark the build as "error". Then Jenkins will see that Maven did not succeed.
You have to set the plugin's configuration so that the build fails upon failed test(s):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
....
<configuration>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
<executions>
....
</executions>
</plugin>

How to generate jar for maven parent project

Maven requires a parent project to have
<packaging>pom</packaging>
clause in the parent's pom.xml. When such a project installed, only a pom-file generated into the maven repository. Jar-file is not generated, no matter if the parent project has any Java code. That forces me to have extra empty parent projects, which is overkill. Logically, some of my libraries could be parents at the same time.
Is there a way to generate both pom and jar files for a parent project without removing/adding the packaging clause between installs?
Use Maven Jar Plugin and Maven Build Helper. Example 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>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>test-${project.version}</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Maven build results:
mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) # test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default) # test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # test ---
[INFO] Installing /home/username/projects/test/pom.xml to /home/username/.m2/repository/test/test/1.0/test-1.0.pom
[INFO] Installing /home/username/projects/test/test-1.0 to /home/username/.m2/repository/test/test/1.0/test-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.805s
[INFO] Finished at: Thu Sep 06 13:33:20 EDT 2012
[INFO] Final Memory: 4M/119M
[INFO] ------------------------------------------------------------------------
A note on Maven practices:
Parent modules are typically where you define the dependencies and plugins used in common by all your child modules. It rarely has output of its own. You probably want to have a "distribution" sub-module that aggregates all your other module artifacts, rather than attempting to do it in the parent module.

Resources