How to ignore maven profiles in child module? - maven

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.

Related

Executing cargo:run from a maven profile

I am trying to write a maven profile that will run the cargo:run goal and will Start a container and wait for the user to press CTRL + C to stop. However when I run mvn clean install -PstartApplication, the command completes successfully without waiting. What am I missing?
<profile>
<id>startApplication</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>true</wait>
<container>
<containerId>tomcat7x</containerId>
<type>installed</type>
<home>${catalina.home}</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.basedir}/target/tomcat7x</home>
</configuration>
<deployables>
<deployable>
<properties>
<context>ROOT</context>
</properties>
<groupId>com.demo.web</groupId>
<artifactId>sample-web-app</artifactId>
<type>war</type>
</deployable>
</deployables>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Check the plugin configuration: the executions element in the code you posted is within the configuration element, which is not correct and as such it will be ignored by Maven. (Check the official documentation for more details).
The executions section should be out of a configuration section (and at the same nested level). They could then also include a further configuration section, which will be the configuration used by that specific wrapping execution, while the previous would be a more generic configuration applied by default to all listed executions.
In this specific case, the Cargo Plugin also provides a further configuration element within the Maven configuration section, which makes things a bit confusing and misleading (a different name should have been chosen, in my opinion).
Hence, in your case, you should move out the executions section from the configuration section, as following:
<profile>
<id>startApplication</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>true</wait>
<container>
<containerId>tomcat7x</containerId>
<type>installed</type>
<home>${catalina.home}</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.basedir}/target/tomcat7x</home>
</configuration>
<deployables>
<deployable>
<properties>
<context>ROOT</context>
</properties>
<groupId>com.demo.web</groupId>
<artifactId>sample-web-app</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Running surefire test on another\diffrent pom.xml file

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>

Starting of the Apache tomcat server before integration test

I've been looking for an solution for the last 4 days and raised this question as a bounty but still not getting my answer.
Where i've succeeded with the help pf pom.xml file:-
a) Starting the tomcat server manually using command i.e mvn tomcat7:run. This command also
help me deploying of my war file to tomcat server and starting the server.
b) Running my integration tests using testng.xml file configuration on eclipse.
Where i'm failed with the help pf pom.xml file:-
a) Automatically starting of tomcat server.
b) Running all the integration tests.
c) Stopping of tomcat server.
This question is posted by me but couldn't find the answer
Starting apache server before integration testing not working
Please help where i'm wrong.
Minimal POM
Here is a minimal POM file that I used to achieve what you want. If it doesn't work for you, please post the output of mvn -X clean verify like #BrennaFlood said. Configurations for tomcat7-maven-plugin and maven-failsafe-plugin taken from http://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html#Use_it_with_selenium_mojo and http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html, respectively.
<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.example</groupId>
<artifactId>tomcat-with-failsafe</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat7-run</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat7-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
It looks like you have tomcat start and stop bound to pre-integration-test and post-integration-test phases, but the TestNG stuff is being run during the test phase, which comes before the integration-test phases. Like the other responder said - you should be running:
mvn clean verify -X
... so that you're catching all the phases up through post-integration-test (and catching all the debug information for troubleshooting), but you should also bind your TestNG components to the integration-test phase.
I just want to add this for anyone that is looking to use maven + tomcat7 + testng. Basically my scenario is that some of our IT test needs the running application so they can send some REST call, but some of the IT does not require the server, I split the test cases in two different suites one for the IT that requires the server in the ServerRequiredIT.xml and others in NonServerRequiredIT.xml, based on that I create two profiles as it follows.
<profiles>
<profile>
<id>run-its</id>
<properties>
<build.profile.id>integration-test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/</path>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx2048m</argLine>
<printSummary>true</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>file:${project.build.testOutputDirectory}/resources/log4j-surefire.properties</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>src/test/scripts/ServerRequiredIT.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>testNG-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx2048m</argLine>
<printSummary>true</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>file:${project.build.testOutputDirectory}/resources/log4j-surefire.properties</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>src/test/scripts/NonServerRequiredIT.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
To run the profiles I use mvn test -P 'nameOfProfile'. Important thing here is what the documentation said
The Failsafe Plugin is designed to run integration tests while the
Surefire Plugin is designed to run unit tests
Hope that helps.

maven release plugin with phase and jar-with-dependencies

I have a build set up to run a variety of tasks when I run mvn release:prepare and mvn:release:perform. Specifically, I have a phase set up so that my javadocs and source-plugins are run only when I release. This allows my build to avoid a lot of time for the common case of mvn clean install. I'd like to add to this my maven-assembly-plugin jar-with-dependencies so only when I release the assembly plugin is run.
Here's what my build looks like:
<?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>example</groupId>
<artifactId>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Example</name>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclet>org.asciidoctor.Asciidoclet</doclet>
<docletArtifact>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoclet</artifactId>
<version>0.1.3</version>
</docletArtifact>
<linksource>true</linksource>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
the maven-source-plugin and maven-javadoc-plugin both run during the release phase, but the maven-assembly-plugin does not. What do I have to do to make this plugin run during a maven release?
The single isn't bound to a default phase, so you have to specify it in the execution-block.
If you compare it with the javadoc:jar you'll see that this goal is by default bound to the package phase.

Maven Wagon plugin: Can wagon:upload upload to multiple locations?

I'm looking into the Maven Wagon Plugin to attempt uploading some artifacts to remote UNC Server shares (\\servername\share\directory\to\put\to), and I have gotten it configured to work like so in the POM:
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>upload-jar-to-folder</id>
<phase>deploy</phase>
<goals>
<goal>upload</goal>
</goals>
</execution>
</executions>
<configuration>
<fromDir>${project.build.directory}</fromDir>
<includes>*</includes>
<url>file://localhost///${servername}/${sharename}</url>
<toDir>directory/to/put/artifact</toDir>
</configuration>
</plugin>
...
</build>
This works great for one server when I pass in -Dservername=x -Dsharename=y, but how can I scale it out so I can run a deploy for QA or Prod where I have multiple servers to deploy to?
I've considered (and written) a script to run mvn wagon:upload -Penvironment# multiple times--once for each server--but this seems flawed to me. If I'm shelling out to a script to handle this process, I could just as well script out the entire deploy, too. However, this takes away from the usefulness of Wagon (and Maven)...
Is there a way to run multiple <executions> for one goal? For instance, running multiple profile configured wagon:upload tasks when I just run mvn deploy -Pqa?
If you want to use multiple profiles you could just use: mvn deploy -Denv=qa and trigger some profiles on this property and define the configuration for your severs in the profiles. For this kind of profile activation look at
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
and search for
-Denvironment=test
Here's an example POM which does two executions of the maven-antrun-plugin in one build:
<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.stackoverflow</groupId>
<artifactId>q5328617</artifactId>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<id>qa1</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>qa1</id>
<phase>test</phase>
<configuration>
<tasks>
<echo level="info">Executing qa1</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
<profile>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<id>qa2</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>qa2</id>
<phase>test</phase>
<configuration>
<tasks>
<echo level="info">Executing qa2</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Resources