Maven deploy:file step: automatically deploy to snapshot or to release repository - maven

I have the following sections in my pom.xml
<repositories>
<repository>
<id>maven-booking-snapshots</id>
<url>https://artifactory.booking.com/maven-booking-snapshots</url>
</repository>
<repository>
<id>maven-booking-releases</id>
<url>https://artifactory.booking.com/maven-booking-releases</url>
</repository>
<distributionManagement>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Snapshot Repository</name>
<url>https://artifactory.com/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>maven-releases</id>
<name>Release Repository</name>
<url>https://artifactory.com/maven-releases</url>
</repository>
</distributionManagement>
and
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.shaded.google</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>hidden.io.netty</shadedPattern>
</relocation>
</relocations>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-nodeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/original-${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>nodeps</classifier>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
When I run the mvn deploy:file the file is going to be uploaded always in the release repository and (I think) the problem is that the <repository> tag of the plugin points to project.distributionManagement.repository.url. At the same time, I cannot make it point to the project.distributionManagement.snapshotRepository because I would like that the deployment destination depends on the version of the pom. How can I achieve such flexibility in the run of the deploy plugin?

Related

Maven: how can I deploy two artifacts with the release plugin?

My project generates two jar: the original-artifact-name.jar and the artifact-name.jar (I have shade plugin setup).
I want to use mvn release:prepare and mvn release:perform and be able to deploy not only the simple jar but also the origial one.
So far I am invoking the mave deploy:file goal manually after the release plugin has been executed. How can I incorporate this step in the release plugin execution?
Edit: this is my attempt with maven-deploy-plugin:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-nodeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/original-${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>nodeps</classifier>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
which for some reasons is deploying the main jar in the snapshot repo, while the nodeps jar in the release repo. This is my repositories setup
<repositories>
<repository>
<id>maven-snapshots</id>
<url>https://repo.com/maven-snapshots</url>
</repository>
<repository>
<id>maven-releases</id>
<url>https://repo.com/maven-releases</url>
</repository>
If you want to deploy additional files, you can configure the deploy:deploy-file goal in the POM.
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>deploy-bo</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/bo.jar</file>
<pomFile>${basedir}/target/somewhere/pom-bo.xml</pomFile>
<url>${project.distributionManagementArtifactRepository.url}</url>
<repositoryId>${project.distributionManagementArtifactRepository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>

ossrh nexus staging - what determines the repository id?

I am deploying my project to maven central and I notice that I have no control on the repository id, which seems to be automatically generated and in my case, seems to be incorrect and hence the deployment fails. I could have done something wrong but I do now know where to look. Any suggestions would be appreciated.
My pom:
<groupId>uk.ac.shef.dcs</groupId>
<artifactId>sti</artifactId>
<version>1.0alpha</version>
<packaging>pom</packaging>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<configuration>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
When running 'mvn clean deploy', it generates log like this:
Uploaded: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/ukacshefdcsjate-1015/uk/ac/shef/dcs
I do not know how it generates this id: ukacshefdcsjate-1015. I thought it should corresponds to the project package path, but my package should be uk.ac.shef.dcs.sti. and I never had a package called 'jate' in my project. In fact, jate is another project I already released to maven central.
And I think it is this problem that after running 'mvn clean deploy', I could not see anything available from: https://oss.sonatype.org/content/repositories/snapshots/

Effective POM is not equal to super POM + project POM?

This question asks what makes up the effective POM. The answer states that effective POM consists of:
Application POM.
Super POM.
settings.xml
Plugins bound to the lifecycle by default based on the packaging type chosen.
I created a minimal POM to observe the effective POM of this minimal POM. The files are as below:
Minimal POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
Super POM:
<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
<profiles>
<!-- NOTE: The release profile will be removed from future versions of the super POM -->
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Effective POM:
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>/Users/utku/Minimal_POM_Test/src/main/java</sourceDirectory>
<scriptSourceDirectory>/Users/utku/Minimal_POM_Test/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>/Users/utku/Minimal_POM_Test/src/test/java</testSourceDirectory>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/classes</outputDirectory>
<testOutputDirectory>/Users/utku/Minimal_POM_Test/target/test-classes</testOutputDirectory>
<resources>
<resource>
<directory>/Users/utku/Minimal_POM_Test/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>/Users/utku/Minimal_POM_Test/src/test/resources</directory>
</testResource>
</testResources>
<directory>/Users/utku/Minimal_POM_Test/target</directory>
<finalName>my-app-1</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
</reporting>
</project>
However, observe the following:
<repositories> tag of the effective POM and the Super POM are not the same:
The order which elements of the <repositories> tag appear are different.
Effective POM is missing the <layout>default</layout> part.
Similar differences exist for other tags as well.
What is the reason for this? Two questions regarding this topic are:
From the linked question, I thought that effective POM is just a summation of the project POM and the Super POM. However the results show that it is not as simple as this. Does further processing goes into the effective POM?
If yes, which Maven plugins (or other tools) are used to create the effective POM?
The <repositories> tags of the effective POM and the Super POM are the same regarding their effective content. <layout>default is, no wonder, the default. The order of declarations usually is not relevant due to the declarative nature of a POM. (If it is it's mentioned in the documentation.)
See Maven: The Complete Reference, 3.2.1. The Super POM for further information.
See also the Maven Model Builder:
The effective model builder, with profile activation, inheritance, interpolation, ...
...
phase 1
...
parent resolution until super-pom
...

OSGi Code Coverage during Integration Testing

I am running integration tests on OSGi bundles using SOAPUI. So far I have integrated SOAPUI with Maven which runs integration tests on OSGi bundles*(running in Apache Karaf)*. I am trying to find out how can I further enhance my pom.xml to calculate code coverage during runtime for the bundles?
Can anyone plz suggest some points?
I have the following 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>org.m2m.aricent.parent</groupId>
<artifactId>CustRestExampleOsgi</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>CustRestExampleOsgii</name>
<modules>
<module>M2mCustImplProvider</module>
<module>M2mCustInterface</module>
<module>M2mRestCustConsumer</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<karaf.deploy.build.folder>
G:\apache-karaf-3.0.0.RC1\deploy
</karaf.deploy.build.folder>
</properties>
<dependencies>
<!-- needed to execute Integration tests instrumented with Cobertura -->
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>1.9.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>eviwarePluginRepository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
<pluginRepository>
<id>cobertura-it-maven-plugin-maven2-release</id>
<url>http://cobertura-it-maven-plugin.googlecode.com/svn/maven2/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.5.1</version>
<configuration>
<junitReport>true</junitReport>
<exportAll>true</exportAll>
<projectFile>C:\Documents and Settings\gur31659.AD\workspace\CustomerRestfulExampleOSGi\test-classes\cust.xml</projectFile>
<outputFolder>C:\Documents and Settings\gur31659.AD\workspace\CustomerRestfulExampleOSGi\test_output</outputFolder>
<testFailIgnore>true</testFailIgnore>
</configuration>
<executions>
<execution>
<id>wsn-server-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-it-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<check>
<haltOnFailure>false</haltOnFailure>
</check>
</configuration>
<executions>
<execution>
<id>cobertura-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>cobertura-instrument</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>cobertura-report</id>
<phase>pre-site</phase>
<goals>
<goal>report-only</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.5.201403032054</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-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 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>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</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>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.2.v20120308</version>
<configuration>
<stopPort>18043</stopPort>
<stopKey>STOP</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>18042</port>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<!-- Needed in order to to code coverage on SoapUI tests -->
<classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
<useTestScope>true</useTestScope>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
<contextPath>/myIntegrationTestsContext</contextPath>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0</version>
<configuration>
<minimumTokens>20</minimumTokens>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-it-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Answer:
I suggest that you should try Jacoco. Jacoco can be configured as a java agent, so it can work with any Java application. In this case, you should configure Jacoco on the Karaf server where you deploy the bundles.
You can configure it as a TCP server so you can check the coverage reports live from Eclipse (it has an Eclipse plugin as well to connect).
Extra:
We use Jacoco with our maven plugin that starts an OSGi container and runs tests on them within the integration-test phase of the build. In case felix or equinox is enough, you can use it as well.
It supports creating custom dist packages so if you bundle your Karaf server as a dist package, it could also be used. Sadly, there still not much documentation about creating custom server types.

How to separate JUnit test and Selenium test using the pom

I have a pom.xml wich is pasted below and I want to know how can I modify it to make it possible to say "mvn unittest" or "mvn seleniumtest" to be able to run the two types of tests separately. Now as the POM is, if I say "mvn test" it runs the tests in my project that ends with "Test", but I cannot understand where in the pom is this defined and how.
The pom:
<?xml version="1.0"?>
<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.magnus.unittest</groupId>
<artifactId>unittestproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.6.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\enhetstesting\unittestproject\src\main\java</sourceDirectory>
<scriptSourceDirectory>C:\enhetstesting\unittestproject\src\main\scripts</scriptSourceDirectory>
<testSourceDirectory>C:\enhetstesting\unittestproject\src\test\java</testSourceDirectory>
<outputDirectory>C:\enhetstesting\unittestproject\target\classes</outputDirectory>
<testOutputDirectory>C:\enhetstesting\unittestproject\target\test-classes</testOutputDirectory>
<resources>
<resource>
<directory>C:\enhetstesting\unittestproject\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>C:\enhetstesting\unittestproject\src\test\resources</directory>
</testResource>
</testResources>
<directory>C:\enhetstesting\unittestproject\target</directory>
<finalName>unittestproject-0.0.1-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
</reporting>
</project>
You can accomplish this with profiles. There is documentation on the official Maven web site, but I like Sonatype's free online book: Maven: The Complete Reference - 5.3. Profile Activation
You will need something like this (see documentation on test exclusions).
Wit the below configuration, you could run mvn test -Pjava-tests or mvn -Psel-tests (just for example - you have several options for profile activation).
<profiles>
<profile>
<id>java-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>path/to/selinum/tests/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sel-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>path/to/selinum/tests/**</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Please note that this is a large topic and the above answer is to get you on the right track. If you have follow-up issues, please consider opening them as new questions. Good luck!

Resources