optimizing maven build performance - maven

I have a Maven web application. This is taking too much time to build(30-40 mins).I would like to reduce it to less than 10 mins. My pom.xml is as 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>se.mysite.etc.settings</groupId>
<artifactId>projects</artifactId>
<version>1.5</version>
</parent>
<groupId>se.myweb.portal</groupId>
<artifactId>myweb-se-main</artifactId>
<name>myweb-se-main</name>
<version>3.1.81-B2_forv-SNAPSHOT</version>
<packaging>pom</packaging>
<inceptionYear>2009</inceptionYear>
<properties>
<release.version>${project.version}</release.version>
<acc.version>2.3.42-TEST-MAINT-SNAPSHOT</acc.version>
<cxf.version>2.5.3</cxf.version>
<spring.version>3.0.3.RELEASE</spring.version>
<spring.security.version>2.0.4</spring.security.version>
<spring.webflow.version>2.1.1.RELEASE</spring.webflow.version>
<commonportal.version>1.9.9-SPRING3</commonportal.version>
<junit.version>4.5</junit.version>
<java.source.version>1.6</java.source.version>
<cobertura.maxmem>1024M</cobertura.maxmem>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<scm>
<connection>scm:hg:http://test1/myweb</connection>
<developerConnection>scm:hg:http://test1/myweb</developerConnection>
<tag/>
<url>http://test1/myweb</url>
</scm>
<profiles>
<profile>
<id>dev</id>
<dependencies>
<!--some dependencies-->
</dependencies>
<modules>
<module>../project1</module>
<module>../project2</module>
<module>../project3</module>
<module>../project4</module>
</modules>
</profile>
<profile>
<id>dist</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<!--some dependencies-->
</dependencies>
<modules>
<module>../project1</module>
<module>../project2</module>
<module>../project3</module>
<module>../project4</module>
<module>../project5</module>
<module>../project6</module>
</modules>
</profile>
<profile>
<id>backend</id>
<dependencies>
<!--some dependencies-->
<modules>
<module>../project3</module>
<module>../project1</module>
<module>../project2</module>
<module>../project4</module>
<module>../project9</module>
</modules>
</profile>
<profile>
<id>frontend</id>
<!--some dependencies-->
<modules>
<module>../project10</module>
<module>../project11</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<forkMode>always</forkMode>
<argLine>-Xms512m -Xmx2048m -XX:MaxPermSize=2048m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>webtest</id>
<build>
<finalName>myweb-web-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:MaxPermSize=512m</argLine>
</configuration>
</plugin>
</plugins>
</build>
<!--some dependencies-->
<modules>
<module>../myweb-web-test</module>
</modules>
</profile>
<profile>
<id>redeploy_web_app</id>
<activation>
<property>
<name>redeployWebApp</name>
</property>
</activation>
<properties>
<user.tomcat.home>${env.DEST_DIR}</user.tomcat.home>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<dependencies>
<!--some dependencies-->
</dependencies>
<executions>
<execution>
<id>delete_project_artifact</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<taskdef classpathref="maven.plugin.classpath" resource="net/sf/antcontrib/antcontrib.properties"/>
<if>
<equals arg1="${project.packaging}" arg2="war"/>
<then>
<echo message="Removing ${project.artifactId}.${project.packaging} from ${user.tomcat.home}/webapps"/>
<delete dir="${user.tomcat.home}/webapps/${project.artifactId}"/>
<delete file="${user.tomcat.home}/webapps/${project.artifactId}.${project.packaging}"/>
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>copy_project_artifact</id>
<phase>package</phase>
<configuration>
<tasks>
<taskdef classpathref="maven.plugin.classpath" resource="net/sf/antcontrib/antcontrib.properties"/>
<if>
<equals arg1="${project.packaging}" arg2="war"/>
<then>
<echo message="Copying ${project.build.finalName}.${project.packaging}"/>
<copy file="${project.build.directory}/${project.build.finalName}.${project.packaging}" overwrite="true" tofile="${user.tomcat.home}/webapps/${project.artifactId}.${project.packaging}"/>
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- General dependencies -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<instrumentation>
<excludes>
<exclude>se.mysite/**/Test*.class</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- TODO: Use UTF-8 here or not??? -->
<encoding>UTF-8</encoding>
<!-- encoding>ISO-8859-1</encoding-->
<source>${java.source.version}</source>
<target>${java.source.version}</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<scmCommentPrefix>II Release:</scmCommentPrefix>
</configuration>
</plugin>
</plugins>
</build>
<organization>
<name>mysite AB</name>
<url>http://www.mysite.se</url>
</organization>
</project>
My compile command is below.
mvn -U -DartifactsTarget=$DEST_DIR/lib/tpp -P dev -Dmaven.test.failure.ignore=true -Dtesting.testsToExclude=**/Test*.java -f pom.xml $* -DredeployWebApp install
It is taking almost 30 mins to build.
I am using maven 3.0.4. I explored that using the following options we can optimize the build time.
Using maven parallel processing
Using plexus compiler plugin
Using maven power shell
Please let me know if I need to any other changes to my pom.xml or any other techniques that would optimize the performance.

Optimizing the Maven build of a Java project comes down to 3 factors:
Compilation and Tests
Complexity of the Maven build
Optimizing the Maven (binary) performance
Compilation and Tests
If, for example, you have GWT in your application and you're compiling for 20 different permutations then this will be a problem if you're doing this the whole time.
There are ways to get around this by maybe only doing the full build when you need to, and otherwise limiting the build by using the draftCompile or optimizationLevel options.
The same thing applies to your tests: if you have hundreds of tests, the length of time that each test takes starts to become significant. Common ways to increase performance in tests are:
Don't use Thread.sleep(..), use mutex's and locks.
Share configuration (persistence units, mocks) across multiple tests instead of doing the setup per test.
Make it a unit test instead of an integration test, unless you really need to. Too many integration tests is a bad code smell, in any case.
Complexity of the Maven Build
If you have 10's or hundreds of modules, with a complex dependency tree, maven will need time to calculate the dependency tree. Use `dependency:analyze' to figure out whether or not there are unused dependencies and remove them.
Also, the number of plugins used in each module's build will increase the build time.
Optimizing Maven (binary) performance
I use the following options:
export MAVEN_OPTS="-Dmaven.wagon.provider.http=httpclient -Dmaven.artifact.threads=12 -Dhttp.tcp.nodelay=false -Xmx2048M -Xss256M -XX:+CMSClassUnloadingEnabled -XX:-UseGCOverheadLimit -XX:MaxPermSize=256M -T2C"
-Dmaven.wagon.provider.http=httpclient:
Changes the http connection mechanism, my theory is that the Apache HttpClient library is faster and better than the default Java HttpURLConnection class
-Dmaven.artifact.threads=12:
The number of threads used to download artifacts.
-Dhttp.tcp.nodelay=false:
Turns off Nagle's algorithm increasing performance (but also bandwidth used). This is a Wagon property.
-T2C: This was an expiremental build introduced in maven 3: the number of threads per build. See Parallel builds in Maven 3
Please feel to edit this post if you have other tips!

Related

Maven release: Developer information missing

Getting this error on mvn release:perform
[ERROR] Repository "comconvertapi-1002" failures
[ERROR] Rule "pom-staging" failures
[ERROR] * Invalid POM: /com/convertapi/client/convertapi/1.7/convertapi-1.7.pom: Developer information missing
Releasing from branch: https://github.com/ConvertAPI/convertapi-java/tree/feature/maven (could this error be related with that?)
This is POM 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.convertapi.client</groupId>
<artifactId>convertapi</artifactId>
<packaging>jar</packaging>
<version>1.8-SNAPSHOT</version>
<name>ConvertAPI Java Client</name>
<description>
The ConvertAPI helps converting various file formats.
Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes.
Merge, Encrypt, Split, Repair and Decrypt PDF files.
And many others files manipulations.
In just few minutes you can integrate it into your application and use it easily.
The ConvertAPI client library makes it easier to use the Convert API from your Java 8 projects without having to
build your own API calls.
</description>
<url>https://www.convertapi.com/</url>
<licenses>
<license>
<name>The MIT License</name>
<url>https://raw.githubusercontent.com/ConvertAPI/convertapi-java/master/LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>jonas</id>
<name>Jonas Jasas</name>
<email>jonas#baltsoft.com</email>
<organization>Baltsoft</organization>
<organizationUrl>http://www.baltsoft.com/</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>+3</timezone>
<properties>
<picUrl>https://avatars3.githubusercontent.com/u/16254748</picUrl>
</properties>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/ConvertAPI/convertapi-java.git</connection>
<developerConnection>scm:git:git://github.com/ConvertAPI/convertapi-java.git</developerConnection>
<url>https://github.com/ConvertAPI/convertapi-java</url>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/examples/*</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
<mavenExecutorId>forked-path</mavenExecutorId>
<arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!-- GPG Signature on release -->
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
It's seem ok, but sometime maven plugins use cache for some info.
Try to clear cache by this sequence of commands:
mvn clean
mvn release:prepare -Dresume=false
mvn release:perform
If it not helped, try to simplify developer section (excluding sequentially properties, timezone and so on)
Publish Requirement
Please check you have fulfill all your publish requirement.
Supply Javadoc and Sources⚓︎
Sign Files with GPG/PGP
Sufficient Metadata
Correct Coordinates
Project Name, Description and URL
License Information
Developer Information
SCM Information

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.

Maven not detecting existing file

I'm writing a pom file to conditionally checkout or update a subdirectory from git. However, it always does a clean checkout. I'm doing this to wrap CI scripts around existing projects without having to change them.
Here's the code (slightly censored, and with the update ommitted):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>standard-php-project</artifactId>
<version>1.0</version>
<properties>
<git.project>Test/Project</git.project>
<git.project.checkout.directory>${basedir}/src/php/main/${git.project}</git.project.checkout.directory>
<git.project.checkout.exists.file>${git.project.checkout.directory}/.git/index</git.project.checkout.exists.file>
</properties>
<scm>
<connection>scm:git:ssh://server/git/${git.project}</connection>
</scm>
<profiles>
<profile>
<id>scm-checkout</id>
<activation>
<file>
<missing>${git.project.checkout.exists.file}</missing>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>echo-missing-file</id>
<phase>generate-sources</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<echos>
<echo>Couldn't find ${git.project.checkout.exists.file}</echo>
</echos>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<id>scm-generate-sources-phase</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${git.project.checkout.directory}</checkoutDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- And another profile for when the file exists, not shown for brevity -->
</profiles>
</project>
I've run mvn compile which tells me the file it tests for, done ls -l on the file to verify it exists, and then run again. For some reason, the test fails.
Help!
Profiles are determined prior to applying properties from the pom
<missing>${git.project.checkout.exists.file}</missing> won't work from the value in your pom.xml
If it was provided on commandline then I believe it would work
Otherwise you need to include the value directly
<missing>/src/php/main/Test/Project/.git/index</missing>
See also Maven profile by user defined property

Maven profile not activated, though property has correct value

I am trying to set-up conditional plugin execution via profiles. The idea is to have a compress/no compress HTML files:
<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>net</groupId>
<artifactId>mavenconditionalexecution</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Maven Conditional Execution</name>
<properties>
<DoCompress>true</DoCompress>
</properties>
<build>
<plugins>
<!-- Clean-up -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>clean</phase>
<configuration>
<target>
<echo message="DoCompress: ${DoCompress}"/>
<delete includeemptydirs="true">
<fileset dir="${basedir}/src/main/webapp/result/" includes="**/*"/>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/webapp/html</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>With Compression</id>
<activation>
<property>
<name>DoCompress</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId>
<artifactId>htmlcompressor-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>html</goal>
</goals>
</execution>
</executions>
<configuration>
<goalPrefix>htmlcompressor</goalPrefix>
<srcFolder>${basedir}/src/main/webapp/html</srcFolder>
<targetFolder>${basedir}/src/main/webapp/result/html</targetFolder>
<removeIntertagSpaces>true</removeIntertagSpaces>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>Without Compression</id>
<activation>
<property>
<name>DoCompress</name>
<value>false</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<target>
<echo message="Copying file"/>
<copy todir="${basedir}/src/main/webapp/result/">
<fileset dir="${basedir}/src/main/webapp/html/" >
<include name="angle.html"/>
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId>
<artifactId>htmlcompressor-maven-plugin</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
It does not matter what value I assign to the DoCompress property, the corresponding profile are not executed. I check the value of the property with an echo. Why? What am I doing wrong?
Is it allowed to activate multiple profiles in a pom.xml using property values?
UPDATE
I have created an incident: I have created an incident: https://jira.codehaus.org/browse/MNG-5235.
If anyone has an operational example of maven profile activation by properties, I am interested. Moreover, does anyone know whether multiple profiles can be activated in the same run via properties? The documentation is not clear about it.
After opening an issue, it turns out this is not a bug, because properties in the section can only be system properties, not properties defined in the pom.xml itself.

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