Jenkins Artifactory Plugin - Maven wrapper not publishing custom artifacts which have been installed - maven

When building my Maven project, I expect the Jenkins Artifactory Plugin to deploy/publish artifacts which I successfully maven-install (ie, copied from the /target folder to my local maven repo).
The Jenkins-Artifactory plugin binds to the install phase of the Maven lifecycle. It is publishing the pom files for the modules of my project, but not the build files I need (which I have installed).
UPDATE: JFrog have confirmed this is a bug with the plugin: https://github.com/jfrog/jenkins-artifactory-plugin/issues/665 - I will post an update to this question once it is resolved.
PLEASE NOTE: A normal pom which simply creates a jar works as expected. This is specifically to do with publishing a custom artifact type having used the maven-install-plugin.
Some details:
The build process creates .bar files
These .bar files are added to /target using the maven-install-plugin execution shown below
The .pom files are being uploaded to Artifactory
The .bar files are not being uploaded to Artifactory
<execution>
<id>custom-install</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<generatePom>true</generatePom>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.build.finalName}.bar</file>
<packaging>bar</packaging>
</configuration>
</execution>
Logs:
16:50:39 [main] INFO org.apache.maven.cli.event.ExecutionEventLogger - --- maven-install-plugin:2.5.2:install-file (custom-install) # MyMavenModule ---
16:50:39 [main] INFO org.codehaus.plexus.PlexusContainer - Installing /opt/jenkins/workspace/my-project/build/develop/2/MyMavenModule/target/MyMavenModule-1.0.0.bar to /home/jenkins-user/.m2/repository/my/project/group/MyMavenModule/1.0.0/MyMavenModule-1.0.0.bar
16:50:40 [pool-1-thread-1] INFO org.jfrog.build.extractor.maven.ArtifactoryManagerBuilder - [pool-1-thread-1] Deploying artifact: https://artifactory.mycompany.com/artifactory/libs-local/my/project/group/MyMavenModule/1.0.0/MyMavenModule-1.0.0.pom
Versions:
Jenkins: 2.332.1
Artifactory: 6.16.0 Pro
Jenkins Artifactory Plugin: 3.16.1
Maven: 3.8.5
Maven install plugin: 3.0.0-M1
Pipeline / Plugin configuration
rtMavenResolver (
id: "resolver-${config.serverKey}",
serverId: config.serverKey,
releaseRepo: config.repos.resolve.release,
snapshotRepo: config.repos.resolve.snapshot
)
rtMavenDeployer (
id: "deployer-${config.serverKey}",
serverId: config.serverKey,
releaseRepo: config.repos.deploy.release,
snapshotRepo: config.repos.deploy.snapshot,
deployArtifacts : config.deployArtifacts,
includePatterns: config.repos.deploy.includePatterns,
excludePatterns: config.repos.deploy.excludePatterns,
properties: config.repos.deploy.properties,
)
rtBuildInfo (
captureEnv: true,
buildName: config.buildName,
buildNumber: config.buildNumber
)
def mvn(goals) {
rtMavenRun (
tool: config.tools.maven,
pom: 'pom.xml',
goals: "-U -e -B -V -Dstyle.color=always $goals",
opts: '-Dmaven.test.failure.ignore=false -Djansi.force=true',
deployerId: "deployer-${config.artifacts.serverKey}",
resolverId: "resolver-${config.artifacts.serverKey}",
buildName: config.artifacts.buildName,
buildNumber: config.artifacts.buildNumber
)
}
<<<snip>>>
mvn 'install -Dmaven.test.skip=true -DskipTests'
Reproducible Example:
pom.xml
<?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/maven-v4_0_0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<url>http://maven.apache.org</url>
<groupId>com.example</groupId>
<artifactId>MyModule</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<exec-maven-plugin-version>1.6.0</exec-maven-plugin-version>
<maven-install-plugin-version>3.0.0-M1</maven-install-plugin-version>
</properties>
<build>
<plugins>
<!-- Note: See 'http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html' for details -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin-version}</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>custom-install</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<generatePom>true</generatePom>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.build.finalName}.bar</file>
<packaging>bar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>Windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<executions>
<execution>
<id>execution.compile.windows.buildBAR</id>
<phase>compile</phase>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<executable>buildBAR.cmd</executable>
<arguments>
<argument>${iib.toolkit.path.windows}</argument>
<argument>${project.artifactId}</argument>
<argument>${project.build.finalName}</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<executions>
<execution>
<id>execution.compile.unix.buildBAR</id>
<phase>compile</phase>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<executable>sh</executable>
<arguments>
<argument>buildBAR.sh</argument>
<argument>${project.artifactId}</argument>
<argument>${project.build.finalName}</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
buildBAR.cmd
SET moduleName=%1
SET barfileName=%2
echo %moduleName% > %barfileName%.bar
buildBAR.sh
#!/bin/sh
moduleName=$1
barfileName=$2
echo $moduleName > $barfileName.bar
mvn clean install yeilds:
PS C:\dev\barbuilder> mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.example:MyModule >------------------------
[INFO] Building MyModule 1.0.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # MyModule ---
[INFO] Deleting C:\dev\barbuilder\target
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:exec (execution.compile.windows.buildBAR) # MyModule ---
C:\dev\barbuilder\target>SET moduleName=MyModule
C:\dev\barbuilder\target>SET barfileName=MyModule-1.0.0-SNAPSHOT
C:\dev\barbuilder\target>echo MyModule 1>MyModule-1.0.0-SNAPSHOT.bar
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) # MyModule ---
[INFO] Skipping artifact installation
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install-file (custom-install) # MyModule ---
[INFO] Installing C:\dev\barbuilder\target\MyModule-1.0.0-SNAPSHOT.bar to C:\Users\denham.coote\AppData\Local\.m2\repository\com\example\MyModule\1.0.0-SNAPSHOT\MyModule-1.0.0-SNAPSHOT.bar
[INFO] Installing C:\Users\DENHAM~1.COO\AppData\Local\Temp\mvninstall1034342466988970935.pom to C:\Users\denham.coote\AppData\Local\.m2\repository\com\example\MyModule\1.0.0-SNAPSHOT\MyModule-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.217 s
[INFO] Finished at: 2022-04-04T12:29:59+01:00
[INFO] ------------------------------------------------------------------------
PS C:\dev\barbuilder>

Related

How do I build 2 docker images from maven, in separate phases?

I use io.fabric8:docker-maven-plugin:0.28.0 in a Maven project and I need to build 2 different Docker images, in different phases:
One for the integration-test phase, to run some database for the integration tests. I would build it with some resources from the project (SQL files defining the schema).
One at the end, after the tests have passed (maybe during package), with the complete application.
My problem is that only the first image is built.
I tried to reference the image aliases in the <configuration> of the <execution> elements, but it doesn't seem to work. Only the first image is considered:
$ mvn install
...
[INFO] --- docker-maven-plugin:0.28.0:build (start) # dmp-example ---
[INFO] Building tar: /home/cosmin/workspaces/photon/test/dmp-example/target/docker/example/db-test/latest/tmp/docker-build.tar
[INFO] DOCKER> [example/db-test:latest] "example-db-test": Created docker-build.tar in 28 milliseconds
[INFO] DOCKER> [example/db-test:latest] "example-db-test": Built image sha256:d8233
[INFO]
[INFO] --- docker-maven-plugin:0.28.0:start (start) # dmp-example ---
[INFO] DOCKER> [example/db-test:latest] "example-db-test": Start container 47883d799641
[INFO]
[INFO] --- docker-maven-plugin:0.28.0:stop (stop) # dmp-example ---
[INFO] DOCKER> [example/db-test:latest] "example-db-test": Stop and removed container 47883d799641 after 0 ms
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # dmp-example ---
[INFO] Installing /home/cosmin/workspaces/photon/test/dmp-example/target/dmp-example-0.0.1-SNAPSHOT.jar to /home/cosmin/.m2/repository/com/example/dmp-example/0.0.1-SNAPSHOT/dmp-example-0.0.1-SNAPSHOT.jar
[INFO] Installing /home/cosmin/workspaces/photon/test/dmp-example/pom.xml to /home/cosmin/.m2/repository/com/example/dmp-example/0.0.1-SNAPSHOT/dmp-example-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- docker-maven-plugin:0.28.0:build (build) # dmp-example ---
[INFO] Building tar: /home/cosmin/workspaces/photon/test/dmp-example/target/docker/example/db-test/latest/tmp/docker-build.tar
[INFO] DOCKER> [example/db-test:latest] "example-packaged": Created docker-build.tar in 6 milliseconds
[INFO] DOCKER> [example/db-test:latest] "example-packaged": Built image sha256:d8233
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
The second image is not created, and the ID of the first one is also used when the second one should be built:
$ docker images "example/*"
REPOSITORY TAG IMAGE ID CREATED SIZE
example/db-test latest d8233ab899d4 7 days ago 1.2MB
Would there be another way of doing it?
This is my 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.example</groupId>
<artifactId>dmp-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.28.0</version>
<configuration>
<images>
<image>
<alias>example-db-test</alias>
<name>example/db-test:latest</name>
<build>
<from>busybox</from>
</build>
</image>
<image>
<alias>example-packaged</alias>
<name>example/packaged:latest</name>
<build>
<from>alpine</from>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<configuration>
<images>
<image>
<alias>example-db-test</alias>
</image>
</images>
</configuration>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<configuration>
<images>
<image>
<alias>example-db-test</alias>
</image>
</images>
</configuration>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>build</id>
<phase>package</phase>
<configuration>
<images>
<image>
<alias>example-packaged</alias>
</image>
</images>
</configuration>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
For keeping the example simple, I used busybox and alpine as the base images, but that has no relevance.
Try moving the full configuration for the image you want into the execution, instead of using global plugin config.
<execution>
<id>build</id>
<phase>package</phase>
<configuration>
<images>
<image>
<alias>example-packaged</alias>
<name>example/packaged:latest</name>
<build>
<from>alpine</from>
</build>
</image>
</images>
</configuration>
<goals>
<goal>build</goal>
</goals>
</execution>

Jmeter- Error in NonGUIDriver java.lang.IllegalArgumentException

Trying to execute .jmx (Jmeter) using maven project.
Created jmx file in Jmeter 3.1 version.
Using jmeter-maven-plugin 2.1.0.
Getting following error while executing in command line using - mvn clean verify
[INFO] P E R F O R M A N C E T E S T S
[INFO] -------------------------------------------------------
[INFO] Invalid value detected for <postTestPauseInSeconds>. Setting pause to 0...
[INFO]
[INFO]
[INFO] Executing test: CCMTestPlan.jmx
[INFO] Writing log file to: E:\jmeter-mvn-master\jmeter-mvn- master\target\jmeter\logs\CCMTestPlan.jmx.log
[INFO] Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'E:\jmeter-mvn-master\jmeter-mvn-master\target\jmeter\testFiles\CCMTestPlan.jmx', missing class com.thoughtworks.xstream.converters.ConversionException:
[INFO] ---- Debugging information ----
[INFO] cause-exception : com.thoughtworks.xstream.converters.ConversionException
[INFO] cause-message :
[INFO] first-jmeter-class : org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67)
[INFO] class : org.apache.jmeter.save.ScriptWrapper
[INFO] required-type : org.apache.jorphan.collections.ListedHashTree
[INFO] converter-type : org.apache.jmeter.save.ScriptWrapperConverter
[INFO] path : /jmeterTestPlan/hashTree/hashTree/hashTree/hashTree[3]/com.atlantbh.jmeter.plugins.jsonutils.jsonpathextractor.JSONPathExtractor
[INFO] line number : 98
[INFO] version : 3.1 r1770033
[INFO] -------------------------------
Following is my pom.xml file
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<testResultsTimestamp>false</testResultsTimestamp>
<jmeterPlugins>
<plugin>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-extras-libs</artifactId>
</plugin>
</jmeterPlugins>
<testFilesIncluded>
<testFilesIncluded>CCMTestPlan.jmx</testFilesIncluded>
</testFilesIncluded>
<jmeterVersion>3.1</jmeterVersion>
</configuration>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-extras-libs</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Does anybody faced this issue?
Dependency configuration has changed in the 2.x versions of the plugin (see https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Adding-additional-libraries-to-the-classpath)
Adding jar's to the /lib/ext directory
You can add any additional Java libraries to JMeter's lib/ext
directory by using the <jmeterExtensions> configuration element.
This uses the Eclipse Aether libraries to perform dependency
resolution.
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins:pom:1.3.1</artifact>
</jmeterExtensions>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
When you define your dependencies properly you will probably see another error because jmeter-plugins depends upon JMeter 2.13 which has a broken maven dependency tree. This is something the jmeter-plugins team needs to fix (they need to release a version of jmeter plugins that depends upon JMeter 3.1).
The build will break because the plugin is trying to download some transitive dependencies for jmeter-plugins that don't exist, you can work around this by setting:
<downloadExtensionDependencies>false</downloadExtensionDependencies>
This does however mean that you will need to manually set all the dependencies that jmeter-plugins depends upon in your <jmeterExtensions> block.
You can use mvn dependency:tree to get the full list of dependencies required for the jmeter-plugins-extras-libs package.
The above information hasn't made it into the Wiki yet (there's an ongoing task to add this information and move everything across to the website), it is however available in the CHANGELOG:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md
use This it will work
<?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>jmeter</groupId>
<artifactId>qbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>qbo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<testResultsTimestamp>false</testResultsTimestamp>
</configuration>
<executions>
<execution>
<configuration>
<testFilesDirectory>src/test/jmeter/</testFilesDirectory>
</configuration>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Maven: Does it work for not Java code?

I'm newbie to maven (just 2 days playing with it).
I've some problems setting up maven with jacoco plugin and surefire/failsafe.
Despite it reads and copies the source files it doesn't compile them!
I set new directories as I don't follow the standard maven directory layout but it seems not working. The problem is that I cannot change my project's layout as it's the company's.
So, Im trying to solved it manually.
pom.xml:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar</groupId>
<artifactId>example-java-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Code Coverage - Maven and JaCoCo running tests</name>
<properties>
<!-- Tell SonarQube to execute unit tests during analysis-->
<sonar.dynamicAnalysis>true</sonar.dynamicAnalysis>
<!-- Tell SonarQube to use Jacoco as the code coverage engine to generate the reports -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<!-- Display logs to see where the analyzer spends time -->
<sonar.showProfiling>true</sonar.showProfiling>
<sonar.branch>14.1</sonar.branch>
<sonar.language>tcl</sonar.language>
<project.exclude.list>target/**</project.exclude.list>
<test.failOnError>true</test.failOnError>
<basedir>.</basedir>
<!-- Used to locate the profile specific configuration file. -->
<build.profile.id>dev</build.profile.id>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Only unit tests are run by default. -->
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
<!-- Define where the jacoco reports are output -->
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
<jacoco.it.execution.destfile>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.destfile>
<jacoco.ut.execution.destfile>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.destfile>
</properties>
<!-- Creating profiles for Development and Integration Testing
'dev' profile (default): used during development, only unit tests are run.
'integration-test' profile: used to run integration tests. -->
<profiles>
<profile>
<id>dev</id>
<!-- Dev profile is active by default -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!--Used to locate the profile specific configuration file-->
<build.profile.id>dev</build.profile.id>
<!-- Only unit tests are run by default. -->
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
<build>
<filters>
<!--Specifies path to the properties file, which contains profile specific configuration-->
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>integration-test</id>
<properties>
<!--Used to locate the profile specific configuration file-->
<build.profile.id>integration-test</build.profile.id>
<!-- Only integration tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<filters>
<!-- Specifies path to the properties file, which contains profile specific configuration. -->
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>all-tests</id>
<properties>
<build.profile.id>all-tests</build.profile.id>
<!-- All tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
</profiles>
<build>
<finalName>maven-integration-testing</finalName>
<sourceDirectory>.</sourceDirectory>
<testSourceDirectory>test/tcl</testSourceDirectory>
<filters>
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>.</directory>
<includes>
<include>*.tcl</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>test/tcl</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.5</compilerVersion>
<source>1.5</source>
<target>1.5</target>
<showWarnings>true</showWarnings>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<!-- States that the plugin's add-test-source goal is
executed at generate-test-sources phase. -->
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<!-- Configures the source directory of integration tests -->
<sources>
<source>test/tcl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- Use the Surefire Maven plugin to run our unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
<configuration>
<!-- Sets the VM argument line used when unit tests are run.
we want to create a code coverage report for our unit tests,
we have to ensure that the JaCoCo agent is running
when our unit tests are run -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<includes>
<include>test/tcl/*.tcl</include>
</includes>
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>
<!-- Failsafe Maven plugin is used to execute our integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<!-- States that both integration-test and verify goals
of the Failsafe Maven plugin are executed. -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- we want to create a code coverage report for our integration tests,
we have to ensure that the JaCoCo agent is running
when our integration tests are run -->
<argLine>${failsafeArgLine}</argLine>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<!-- JaCoCo Maven Plugin
1) provides us an access to the JaCoCo runtime agent which records
execution coverage data.
2) creates code coverage reports from the execution data recorded
by the JaCoCo runtime agent.
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<!-- Make the agent run before the tests are run -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Make sure that the jacoco report task is run when package is executed -->
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--Ensures that the code coverage report for unit tests is
created after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Failsafe plugin is executed. -->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent.-->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests after integration tests have been run.-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- TESTING DEPENDENCIES -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</project>
.
**output**:
[INFO] ------------------------------------------------------------------------
[INFO] Building Code Coverage - Maven and JaCoCo running tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (jacoco-initialize) # example-java-maven ---
[INFO] surefireArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/util/target/coverage-reports/jacoco-ut.exec
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (pre-unit-test) # example-java-maven ---
[INFO] surefireArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/util/target/coverage-reports/jacoco-ut.exec
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # example-java-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 41 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # example-java-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-test-source (add-integration-test-sources) # example-java-maven ---
[INFO] Test Source directory:util/test/tcl added.
[INFO]
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) # example-java-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # example-java-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.16:test (default-test) # example-java-maven ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (post-unit-test) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- maven-jar-plugin:2.2:jar (default-jar) # example-java-maven ---
[INFO] Building jar:util/target/maven-integration-testing.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (jacoco-site) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (pre-integration-test) # example-java-maven ---
[INFO] failsafeArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=util/target/coverage-reports/jacoco-it.exec
[INFO]
[INFO] --- maven-failsafe-plugin:2.16:integration-test (integration-tests) # example-java-maven ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (post-integration-test) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- maven-failsafe-plugin:2.16:verify (integration-tests) # example-java-maven ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-install-plugin:2.3:install (default-install) # example-java-maven ---
[INFO] Installing util/target/maven-integration-testing.jar to .m2/repository/org/codehaus/sonar/example-java-maven/1.0-SNAPSHOT/example-java-maven-1.0-SNAPSHOT.jar
[INFO] Installing util/pom.xml to .m2/repository/org/codehaus/sonar/example-java-maven/1.0-SNAPSHOT/example-java-maven-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.054s
[INFO] Finished at: Fri Jan 03 13:35:38 GMT 2014
[INFO] Final Memory: 12M/132M
[INFO] ------------------------------------------------------------------------
>
EDIT:
Also, I wonder if Maven works for projects not with Java code.
Is there any way to make it support a scripting language? And run its tests?

Maven: Can't Launch Plugins on JAR project in pre-integration-test and post-integration-test phases

I am writing a JAR file that acts as a client to the Jenkins CI webapp. Therefore, my project has jar packaging, not war packaging. However, for integration testing, I need to deploy the Jenkins WAR to test my JAR classes against.
I am using the cargo-maven2-plugin, and have it set up so that I can launch Jenkins from the command line with "mvn cargo:run" However, running "mvn install" gets into the integration-test phase without attempting to launch Jenkins with Cargo. In fact, the output of "mvn install -X" doesn't even mention the word "cargo".
It looks like I have bound cargo to pre-integration-test and post-integration-test correctly, but it just won't fire off.
POM below:
<?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>com.phoenix.build</groupId>
<artifactId>HostOp</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.port>53657</jetty.port><!-- mnemonic: 'JENKS' on a telephone -->
</properties>
<name>Host Operations</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<systemProperties>
<property>
<name>maven.output.dir</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
<systemProperties>
<JENKINS_HOME>target/test-classes/jenkins_home</JENKINS_HOME>
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>53657</cargo.servlet.port>
<cargo.jvmargs>-DJENKINS_HOME=target/test-classes/jenkins_home</cargo.jvmargs>
</properties>
<deployables>
<deployable>
<type>war</type>
<location>target/test-classes/jenkins.war</location>
<pingURL>http://localhost:53657/jenkins/view/All/newJob</pingURL>
</deployable>
</deployables>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</project>
How can I get this to fire as needed?
Your posted pom works as expected for me. I just dropped it into an empty project, and:
$ mvn install
[...]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # cargo-plugin-test ---
[...]
[INFO] --- maven-surefire-plugin:2.7.2:test (integration-tests) # cargo-plugin-test ---
[...]
[INFO] --- cargo-maven2-plugin:1.2.1:start (start-container) # cargo-plugin-test ---
[INFO] [2.ContainerStartMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-jetty:jar:1.2.1 for container jetty6x
[INFO] [beddedLocalContainer] Jetty 6.x Embedded starting...
[...]
2012-04-27 15:01:02.457:WARN::Web application not found target/test-classes/jenkins.war
2012-04-27 15:01:02.457:WARN::Failed startup of context
[...]
2012-04-27 15:01:02.741:INFO::Started SelectChannelConnector#0.0.0.0:53657
[INFO] [beddedLocalContainer] Jetty 6.x Embedded started on port [53657]
[...]
That's with Maven 3.0.3:
$ mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: /home/ryan/dev/tools/maven
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: /home/ryan/dev/tools/jdk1.7.0_03/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.0.0-17-generic", arch: "amd64", family: "unix"
I'm not sure what else it might be.

Maven exec plugin execution conundrum

Sample maven build file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-one</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation one"</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-two</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation two"</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
Sample maven output:
$ mvn install
/cygdrive/c/Program Files/Java/jdk1.5.0_20/bin/java -classpath C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/boot/classworlds-1.1.jar -Dclassworlds.conf=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/bin/m2.conf -Dmaven.home=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1 org.codehaus.classworlds.Launcher "install"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - test:test:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:exec {execution: my-validation-one}]
[INFO] "My validation two"
[INFO] [exec:exec {execution: my-validation-two}]
[INFO] "My validation two"
[INFO] [resources:resources {execution: default-resources}]
<snip>
Shouldn't my-validation-one echo "My validation one" to the console? Why does it seem like maven is getting its wires crossed?
Thanks,
Steven
You should put the configuration specific to the execution within the execution block. Then it should work correctly.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-two</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation two"</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Also, if both the executions are bound to same phase and goal, you can combine then within executions block instead of declaring the plugin twice.

Resources