Running surefire test on another\diffrent pom.xml file - maven

I have 2 pom.xml-
one is for testing and the second is for running jetty with war deployment.
How can I run surefire tests on the second pom, when I'm running the first pom?
I tried to call it as a profile in the first pom and the surefire plugin is
started but it doesn't run my tests.
12:01:24 [INFO] --- maven-surefire-plugin:2.16:test (integration-test) # apm-tests ---
12:01:32 [INFO] No tests to run.
pom structure:
<parent>
<artifactId>apm-root</artifactId>
<groupId>com.platform</groupId>
<version>12.50.9999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-tests</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
</dependency>
</dependencies>
<profile>
<id>generate-schema</id>
<build>
<plugins>
<plugin>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>start-jetty</id>
<build>
<plugins>
<plugin>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>tests</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
<argLine>-Xmx1536m</argLine>
<testSourceDirectory>path_to_tests(2nd pom)</testSourceDirectory>
<includes>
<include>path_to_tests/**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Related

How rerun failed test cases of cucumber-jvm in jenkins

How to rerun failed test cases of cucumber-jvm in jenkins?
According to answers mentioned in this thread:
How to rerun failed test cases in cucumber-jvm?
There is different maven command to move and run scenarios for rerun.txt. How to execute them in Jenkins with separate maven command for rerun?
I use cucumber-serenity framework, which uses cucumber-jvm in the background to run everything. Here are the relevant parts of my pom.
I have everything in a separate project, not mixed with any other code. If this is not your case, the following might break your build!
I turn off unit tests:
<build>
<plugins>
<!-- no unit tests: skip anything named *Test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
This does not relate to your question, but I manage all my selenium browser drivers with:
<!-- docs: https://ardesco.lazerycode.com/testing/webdriver/2012/08/12/introducing-the-driver-binary-downloader-maven-plugin-for-selenium.html -->
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver-binary-downloader.plugin.version}</version>
<configuration>
<rootStandaloneServerDirectory>${project.basedir}/selenium/bin</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/selenium/zip</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/RepositoryMap.xml</customRepositoryMap>
<overwriteFilesThatExist>true</overwriteFilesThatExist>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
I use the failsafe-plugin to run my integration tests:
<!-- integration tests: run everything named *IT -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<systemPropertyVariables>
<!-- set by driver-binary-downloader-maven-plugin -->
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above will not rerun any failed tests, which is what you probably want when you run stuff locally on your machine.
On Jenkins only, I turn on the rerunning of failed tests:
<profiles>
<profile>
<id>jenkins</id>
<activation>
<property>
<name>env.JENKINS_HOME</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.plugin.version}</version>
</dependency>
</dependencies>
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I pasted the following in my Pom.xml file and I do not see any failed test case rerunning in Jenkins. Can you explain how to configure this Jenkins please
<profiles>
<profile>
<id>jenkins</id>
<activation>
<property>
<name>env.JENKINS_HOME</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

JUnit - run tests in a category only if specific profile is active

I have the following tests:
FirstUnitTest.java
SecondUnitTest.java
FirstIntegrationTest.java
SecondIntegrationTest.java
The unit tests are not marked with a category.
The two integration tests are marked with #Category(IntegrationTests.class).
I want by default to run all tests EXCEPT for the integration tests.
If, however, a profile integration-tests-only is active, i want to run ONLY the integration tests.
I naively thought the following configuration would make this work:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>com.example.IntegrationTests</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration-tests-only</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>com.example.IntegrationTests</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
But while running the tests without a profile does exactly what I want - run only the unit tests, if I activate the integration-tests-only profile no tests run at all.
Any ideas what I'm doing wrong?
I assume that this happens because you include and exclude, and Maven merges the configurations and resolves to run nothing.
Consider this re-write of the config (did not run it so might have some minor issues):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skipUnitTests}</skip>
<excludedGroups>com.example.IntegrationTests</excludedGroups>
</configuration>
</execution>
<execution>
<id>integ-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skipIntegTests}</skip>
<groups>com.example.IntegrationTests</groups>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>no-tests</id>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
<profile>
<id>unit-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<skipUnitTests>false</skipUnitTests>
<skipIntegTests>true</skipIntegTests>
</properties>
</profile>
<profile>
<id>integ-tests</id>
<properties>
<skipUnitTests>true</skipUnitTests>
<skipIntegTests>false</skipIntegTests>
</properties>
</profile>
</profiles>

How to ignore maven profiles in child module?

I want to run the simple flow, I have 6 profiles:
generate-schema,unpack-war,run-jetty,test,stop-jetty,start-stop-app
the test profile will run on a different child module when I declare it in the mvn goals/properties:
* clean --activate-profiles generate-schema,unpack-war,start-stop-app,test --projects apm-tests,apm-tests\apm-adapter-tests verify.*
How can I make the child module run only the tests and skip the rest of the profiles (generate-schema and etc.) ?
Parent pom sample:
<?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">
<project>
<parent>
<artifactId>apm-root</artifactId>
<groupId>com.apm.platform</groupId>
<version>12.50.9999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-tests</artifactId>
<packaging>pom</packaging>
<modules>
<module>alm-coverage-report</module>
</modules>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-schema</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-schema</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.apm.platform.siteadmin.setup.Setup</mainClass>
<classpathScope>test</classpathScope>
<systemProperties>
<systemProperty>
<key>InstallationFolder</key>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<key>RepositoryFolder</key>
<value>${tests.runtime}/repository</value>
</systemProperty>
<systemProperty>
<key>LogFolder</key>
<value>${tests.runtime}/log</value>
</systemProperty>
<systemProperty>
<key>mercury.td.sa_config_dir</key>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<key>CreateLabProject</key>
<value>${create.lab.project}</value>
</systemProperty>
</systemProperties>
<arguments>
<argument>--auto</argument>
<argument>${db.schema}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>start-jetty</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<war>${unpacked.war.directory}</war>
<contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
<webApp>
<contextPath>/qcbin</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>mercury.td.sa_config_dir</name>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<name>jetty.port</name>
<value>${jetty.start.port}</value>
</systemProperty>
</systemProperties>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>false</daemon>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>start-stop-app</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<war>${unpacked.war.directory}</war>
<contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
<webApp>
<contextPath>/qcbin</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>mercury.td.sa_config_dir</name>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<name>jetty.port</name>
<value>${jetty.start.port}</value>
</systemProperty>
</systemProperties>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>stop-jetty</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- create project profile -->
<profile>
<id>create-project</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<serverUrl>http://localhost:${env.JETTY_PORT}/qcbin</serverUrl>
<saUser>sa</saUser>
<projectUserName>restuser</projectUserName>
<domain>UNITEST</domain>
<project>resttest</project>
<overwrite>true</overwrite>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.apm.maven.plugins.alm</groupId>
<artifactId>rest-create-project</artifactId>
<version>1.0.8.2</version>
<executions>
<execution>
<id>clean-create</id>
<phase>pre-integration-test</phase>
<goals>
<goal>create-project</goal>
</goals>
<configuration>
<serverUrl>${serverUrl}</serverUrl>
<saUser>${saUser}</saUser>
<projectUserName>${projectUserName}</projectUserName>
<projectUserPassword>${projectUserPassword}</projectUserPassword>
<domain>${domain}</domain>
<project>${project}</project>
<overwrite>${overwrite}</overwrite>
<extensions>${extensions}</extensions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Child module 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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.apm.platform</groupId>
<artifactId>apm-tests</artifactId>
<version>12.50.9999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-adapter-tests</artifactId>
<packaging>pom</packaging>
<properties>
<tests.version>${project.version}</tests.version>
</properties>
<dependencies>
<dependency>
<groupId>com.apm.platform</groupId>
<artifactId>apm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
</dependency>
</dependencies>
<profiles>
<!--run integration tests using surefire plugin -->
<profile>
<id>itest</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludedGroups>com.apm.platform.CAPQIntegrationTestCategory</excludedGroups>
<skipTests>false</skipTests>
<excludes>
<exclude>junit/**/*.java</exclude>
<exclude>org/**/*.java</exclude>
</excludes>
<argLine>-Xmx1536m</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sync-adapter</id>
<dependencies>
<dependency>
<groupId>com.apm.platform</groupId>
<artifactId>apm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<!--copies dependent classes from test-jars-->
<id>unpack-tests</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.apm.platform</groupId>
<artifactId>agm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
<outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
13:03:13 2015-11-30 13:03:14.422:INFO:oejs.Server:main: Started
#207555ms 13:03:13 [INFO] Started Jetty Server 13:03:13 [INFO]
13:03:13 [INFO] --- maven-surefire-plugin:2.16:test (integration-test)
# apm-tests --- 13:03:14 [INFO] No tests to run. 13:03:14 [INFO]
13:03:14 [INFO] --- jetty-maven-plugin:9.1.3.v20140225:stop
(stop-jetty) # apm-tests --- 13:03:14 [INFO] 13:03:14 [INFO] ---
maven-source-plugin:2.2.1:jar-no-fork (attach-sources) # alm-tests ---
13:03:14 2015-11-30
13:03:14.820:INFO:oejs.ServerConnector:ShutdownMonitor: Stopped
ServerConnector#4c8d3b5c{HTTP/1.1}{0.0.0.0:5729} 13:03:14 [INFO]
13:03:14 [INFO] --- maven-source-plugin:2.2.1:test-jar-no-fork
(attach-test-sources) # alm-tests --- 13:03:14 [INFO]
13:03:14 [INFO]
--------------- 13:03:14 [INFO] Building agm-synchronizer-adapter-testing
12.50.9999-SNAPSHOT 13:03:14 [INFO] ------------
Please let me clarify few important points which could also potentially solve your issue since I see some good practices may be missing in your approach:
Profiles should be used for optional/additional behaviors, while default build should always be SUCCESSFUL regardless of the declared profiles
If a module is supposed to execute tests and tests are only located in that module, then the profile should only be declared in that specific module and not in its parent. Moreover, in such a case a profile would also not be required since it would be the default module behavior. However, having a profile defined only in a module would allow you to switch it off even when executing the whole build from the parent. To switch off a profile simply use the ! or the - annotation: mvn clean install -P!profile-name as explained in the official documentation here. That will allow to ignore maven profiles in child module (to come to your questions) if the profile was only declared in that module.
You can apply the same concept to the generate-schema action: is it required in all modules? Probably not, then you can declare the profile only on the specific module requiring it and then switch it on/off as above (if by default should be on, then declare the profile as active by default).
Concerning jetty, integration tests requiring jetty should also be part of the same module, so that the module's build would follow the classic flow: start/test/stop.
If you really need to have start, test and stop in different modules, then you can follow explanation on our previous question, here.
I would also suggest to go through the Profile Pitfalls of the Maven official documentation, again, here for a better understanding of profile usage and misuses.
Additionally, if of any help, you can even skip an entire module build as part of a multimodule maven build, using the command line -pl option. Check mvn -help for further details. As such you could supply the list of modules to build. Since maven 3.2.1 you can also supply the list of modules to skip as following: mvn -pl !module-to-skip install.
When using the ! notation for skipping profiles or modules, beware that it is also a special character for bash in linux, hence put it between single quotes (mvn -pl'!module-to-skip' install). The same doesn't work on Windows however, where double quotes should be used instead (mvn -pl "!module-to-skip" install`).
Additionally, to skip modules as part of the parent build, you could also define a profile in your parent POM which re-declares the modules section and omit the modules you want to skip, as explained in this other answer.
...
<modules>
<module>module1</module>
<module>module2</module>
...
</modules>
...
<profiles>
<profile>
<id>skip-some-modules-profile</id>
<modules>
<module>module1</module>
...
<module>module-integration-test</module>
</modules>
</profile>
</profiles>
...
As such, you could craft a special multimodule build depending on the profile you want to execute.
All in all, beware that playing too much with profiles and modules which don't deliver any real artefact may affect your build readability and maintenance.

Can't bind maven-remote-resources-plugin to both bundle and process goals

I use the maven-remote-resources-plugin to get some resources from an artifact and also need to bundle some resources for use in another project.
I bind the maven-remote-resources-plugin to the bundle goal in the default section (not in a profile). And I bind the maven-remote-resources-plugin to the process goal in a profile.
My problem is that I don't get the shared resources when using the profile (I don't get the target\maven-shared-archive-resources folder).
If I remove the maven-remote-resources-plugin in the default section (the bundle binding) it works fine.
Any suggestions?
Below is my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<dependencies>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
<resourcesDirectory>${basedir}/src/test/resources</resourcesDirectory>
<includes>
<include>**/*.sql</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>create-test-data</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>com.mycompany.app:my-app-common:1.0-SNAPSHOT:test-jar</resourceBundle>
</resourceBundles>
<attachToMain>false</attachToMain>
</configuration>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
The problem was that the property outputDirectory is defined for both the process and bundle goals and I redefined it in the bundle goal.

Maven tests run twice when a profile identifier is in multiple projects. Why?

I have numerous projects in IntelliJ, each of which has a pom.xml, and each of the projects' poms inherit from the master pom.xml. One profile (called test1) is present in two of the poms (for project2 and project4). When I run maven from the command line, specifying one project and the profile name, it works (the tests in that project are executed once) Here is the commmand:
mvn test -pl project2 -am -P test1
When I specify both projects (both of which have the same profile present), the tests in project4 are executed twice. Here is the command:
mvn test -pl project2,project4 -am -P test1
I would like the tests only to be executed once. I am running maven 3.1.1.
As a further complication, when I specify just project4, the tests in project2 get executed once, and the tests in project4 don't get executed at all. Here is the command:
mvn test -pl project4 -am -P test1
Here is pom.xml for project2:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns stuff...>
<parent>
<artifactId>parent artifact id</artifactId>
<groupId>group id</groupId>
<version>version</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>project2</name>
<artifactId>project2</artifactId>
<packaging>jar</packaging>
<profiles>
<profile>
<id>test1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>execute-tests-1</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>com/path/to/exclude/**/*.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<!-- We don't want to run any tests without an active profile -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- This exports the classes in the tests for use with our other modules' tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
[ dependencies ...]
</dependencies>
</project>
Here is the pom.xml for project4:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns stuff>
<parent>
<artifactId>[parent artifact id]</artifactId>
<groupId>[group id]</groupId>
<version>[version]</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>project4</name>
<artifactId>project4</artifactId>
<packaging>jar</packaging>
<dependencies>
[ dependencies ...]
</dependencies>
<profiles>
<profile>
<id>test1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>execute-tests-2</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>com/path/to/tests/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
[ dependencies...]
</dependencies>
</profile>
</profiles>
</project>
I figured out the answer to my own question (by looking carefully at some of our other projects' Maven test setup). I had to do two things:
Include a <skip>false</skip> element in the <configuration> aggregate in the surefire plugin.
Include a generic surefire <plugins> aggregate outside of the <profiles> section. This one has <skip> set to true and prevents tests being run unless they are in a profile. Here is what the section looks like:
<build>
<plugins>
<!-- We don't want to run any tests without an active profile -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
The problem was that the tests were running the default-test lifecycle phase and then they were running again in the test phase. After I made the change they only ran in the test phase.

Resources