how to deploy web app to jetty - selenium-rc

I have an web app(actually a gwt app), and i want to deploy it to Jetty server for selenium testing, i used maven, maven-jetty-plugin, gwt-maven-plugin and selenium-maven-plugin, i finally got jetty and selenium sever running but the selenium tests fail because of the famous 404 eror:
com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://127.0.0.1:8080/index.html Response_Code = 404 Error_Message = Not Found
i m not sure if my jetty configuration is correct since i m kind of new to it, here is it(maven-jetty-plugin):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/sample-console</contextPath>
<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integraion-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
when i ran mvn clean install, i can see the output from command window:
[INFO] Configuring Jetty for project: DYI sample Console
[INFO] Webapp source directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Reload Mechanic: automatic
[INFO] Classes = /Users/dyi/Documents/workspace/sample/console/target/classes
log4j:WARN No appenders could be found for logger (org.mortbay.log).
log4j:WARN Please initialize the log4j system properly.
[INFO] Context path = /sample-console
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT/WEB-INF/web.xml
[INFO] Webapp directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Starting jetty 6.1.22 ...
[INFO] Started Jetty Server
[INFO] [selenium:start-server {execution: start}]
and my folder structure looks like this:
--sample/
-- console/
-- src/
-- target/
-- classes/
-- sample-console-0.1-SNAPSHOT/
-- css/
-- images/
-- img/
-- index.html
-- js/
-- META-INF/
-- security/
-- test.html
-- WEB-INF/
-- classes/
-- lib/
-- web.xml
the thing i don't understand is i can see the index.html page is right there in the folder 'sample-console-0.1-SNAPSHOT', why it cannot find it? is that because i set the 'contextPath' wrong? i tried setting it to '/', then i got 503 service not available error. anyone can help? much thanks!!

It sounds like you're trying to run the app out of the webapp directory, which won't work in a GWT app. Try setting the goal in your jetty maven plugin to be run-war instead of run, like this:
<modelVersion>4.0.0</modelVersion>
<groupId>org.proj.web</groupId>
<artifactId>gwtapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>gwtapp</name>
<properties>
...
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<excludes>
<exclude>**/integration/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/integration/**
</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<!-- Selenium and integration testing support -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<webAppConfig>
<contextPath>/${project.name}</contextPath>
</webAppConfig>
<scanIntervalSeconds>5</scanIntervalSeconds>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<logLevel>INFO</logLevel>
<style>PRETTY</style>
<runTarget>/gwtapp.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<modules>
<module>${project.groupId}.gwtapp</module>
</modules>
<copyWebapp>true</copyWebapp>
</configuration>
<executions>
<execution>
<id>gwtcompile</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
</build>
This will cause the compile and gwt-compile to run., assuming you have those configured correctly.
If your config looks like this, you can just run mvn clean integration-tests and your script will:
Compile your code
gwt:compile your code
Create the war file
start jetty and deploy the war file to jetty
Start the Selenium server
try to run any tests in any subdirectory of the integration package in your test directory.

Related

Jacoco analyzed bundle '...' with 0 classes when used with Cucumber

I am currently working on Jacoco code coverage for a Maven project with Cucumber integration tests.
My pom.xml file has jacoco and failsafe plugins as shown in the pictures, with reference from https://github.com/dimazelinskyi/jacoco-coverage-cucumber-unit-tests.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.basedir}/target/jacoco-reports/jacoco-test.exec</destFile>
<propertyName>failsafeJacocoAgent</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.basedir}/target/jacoco-reports/jacoco-test.exec</dataFile>
<outputDirectory>${project.basedir}/target/jacoco-reports/jacoco-test</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
<execution>
<id>junit-integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
<execution>
<id>testng-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/CukeRunnerTest.java</include>
</includes>
<systemPropertyVariables>
<isMavenTest>true</isMavenTest>
<client.uri>${wipdm.app.base.url}</client.uri>
<cucumber.options>${async.option}</cucumber.options>
</systemPropertyVariables>
<properties>
<async.option>--tags ~#longRunningTest</async.option>
</properties>
</configuration>
</plugin>
And the CukeRunnerTest.java file looks like this: CukeRunnerTest.java
When I build with maven i.e. mvn clean install, all tests successfully pass, however I get a message saying
[INFO] Loading execution data file C:\Users\...\IdeaProjects\...\target\jacoco-reports\jacoco-test.exec
[INFO] Analyzed bundle 'wipdata-war' with 0 classes
The build is successful and jacoco-it.exec file is generated, but no reports are generated.
Is this expected behaviour? As I thought that jacoco would check the Cucumber feature files inside "src/test/features/v3" (which is stated inside CukeRunnerTest.java) to see which code in the java files they covered in their integration tests.
Any advice or help is much appreciated.

Springboot failsafe multi-module integration test

I have to run integration-test with fail safe and my project is a multi module project, with one module for selenium test and another one with the actual web app.
I want to run the web app then the test over this app and then stopping this app and getting the report of the integration tests.
In order to do this I used this, inside the pom of the selenium test module :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<includes>
<include>
<groupId>com.example</groupId>
<artifactId>web-app</artifactId>
</include>
</includes>
<mainClass>com.example.App</mainClass>
<arguments>
<argument>--server.port=${tomcat.http.port}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<test.server.port>${tomcat.http.port}</test.server.port>
</systemPropertyVariables>
</configuration>
</plugin>
The error I get is that the main class is not found :
java.lang.ClassNotFoundException: App
It feels like inside the selenium test I can't get to the webapp classPath, It seems like its trying to run the selenium test main instead of the webapp's one

Getting 0% coverage report using jacoco-gwt-maven-plugin?

I am trying to get coverage report of GWTTestCases using jacoco-gwt-maven-plugin.
I followed the below link:
https://github.com/errai/jacoco-gwt-maven-plugin
pom.xml
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jboss.errai</groupId>
<artifactId>jacoco-gwt-maven-plugin</artifactId>
<version>0.5.4.201202141554</version>
<configuration>
<snapshotDirectory>${project.build.directory}/test-classes</snapshotDirectory>
<propertyName>jacocoArgs</propertyName>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<argLine>${jacocoArgs}</argLine>
</configuration>
</plugin>
</plugins>
</build>
When I run the Project using commands as,
mvn clean
mvn install
Inside target folder I can see,
site Directory --> jacoco Directory --> index.html file gets created.
When I open index.html, code coverage is 0%.
What I am doing wrong, Please help.
I got some help from link below, but still struggling to get complete report
How do I setup coverage with GWT, maven, jacoco?
In target\test-classes folder I can see only GwtTestCovergeSample.class file from test package, does client and server folder class files should also be present here?

Maven Jacoco Configuration - Exclude classes/packages from report not working

I have a maven multi-module project and I'm using jacoco-maven for code coverage reports. Some classes should not be reported, as they're Spring configuration and I'm not interested in them.
I have declared the maven-jacoco plugin as follow:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<exclude>some.package.*</exclude>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
<exclude>some/package/SomeClass.java</exclude>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is that when I execute mvn clean verify jacoco still reports classes that should have been excluded as my xml configuration points out. How can I configure it properly?
Your XML is slightly wrong, you need to add any class exclusions within an excludes parent field, so your above configuration should look like the following as per the Jacoco docs
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<configuration>
<excludes>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The values of the exclude fields should be class paths (not package names) of the compiled classes relative to the directory target/classes/ using the standard wildcard syntax
* Match zero or more characters
** Match zero or more directories
? Match a single character
You may also exclude a package and all of its children/subpackages this way:
<exclude>some/package/**/*</exclude>
This will exclude every class in some.package, as well as any children. For example, some.package.child wouldn't be included in the reports either.
I have tested and my report goal reports on a reduced number of classes using the above.
If you are then pushing this report into Sonar, you will then need to tell Sonar to exclude these classes in the display which can be done in the Sonar settings
Settings > General Settings > Exclusions > Code Coverage
Sonar Docs explains it a bit more
Running your command above
mvn clean verify
Will show the classes have been excluded
No exclusions
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) # ** ---
[INFO] Analyzed bundle '**' with 37 classes
With exclusions
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) # ** ---
[INFO] Analyzed bundle '**' with 34 classes
Though Andrew already answered question with details , i am giving code how to exclude it in pom
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<excludes>
<exclude>**/*com/test/vaquar/khan/HealthChecker.class</exclude>
</excludes>
</configuration>
<executions>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
For Springboot application
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude class from test coverage -->
<exclude>**/*com/khan/vaquar/Application.class</exclude>
<!-- Exclude full package from test coverage -->
<exclude>**/*com/khan/vaquar/config/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Another solution:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<excludes>
<exclude>com.mypackage1</exclude
<exclude>com.mypackage2</exclude>
</excludes>
<element>PACKAGE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.85</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Please note that, we are using "<element>PACKAGE</element>" in the configuration which then helps us to exclude at package level.
you can configure the coverage exclusion in the sonar properties, outside of the configuration of the jacoco plugin:
...
<properties>
....
<sonar.exclusions>
**/generated/**/*,
**/model/**/*
</sonar.exclusions>
<sonar.test.exclusions>
src/test/**/*
</sonar.test.exclusions>
....
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.coverage.exclusions>
**/generated/**/*,
**/model/**/*
</sonar.coverage.exclusions>
<jacoco.version>0.7.5.201505241946</jacoco.version>
....
</properties>
....
and remember to remove the exclusion settings from the plugin
Some Examples from the SonarQube Docs:
Use sonar.coverage.exclusions property.
mvn clean install -Dsonar.coverage.exclusions=**/*ToBeExcluded.java
This should exclude the classes from coverage calculation.
This Work Like a charm with Spring Boot 2.5.3 and Jacoco 0.8.4 ^_^
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<output>file</output>
<append>true</append>
<excludes>
<exclude>**/*com/example/Application.class</exclude>
<exclude>**/*com/example/modal*/**</exclude>
<exclude>**/*com/example/dto*/**</exclude>
<exclude>**/*com/example/mapper*/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
https://github.com/jacoco/jacoco/issues/34
These are the different notations for classes we have:
VM Name: java/util/Map$Entry
Java Name: java.util.Map$Entry File
Name: java/util/Map$Entry.class
Agent Parameters, Ant tasks and Maven prepare-agent goal
includes: Java Name (VM Name also works)
excludes: Java Name (VM Name also works)
exclclassloader: Java Name
These specifications allow wildcards * and ?, where * wildcards any number of characters, even multiple nested folders.
Maven report goal
includes: File Name
excludes: File Name
These specs allow Ant Filespec like wildcards *, ** and ?, where * wildcards parts of a single path element only.
Here is the working sample in pom.xml file.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>PACKAGE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.00</minimum>
</limit>
</limits>
</rule>
</rules>
<excludes>
<exclude>com/pfj/fleet/dao/model/**/*</exclude>
</excludes>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>

Maven Plugin for calling Maven Plugins?

does anyone know any maven plugin that can call other maven plugins in a generic way? What I am searching for is anything like a proxy mechanism for scheduling plugin executions in a specific order.
The key is that I have to migrate a huge legacy project to maven which has plenty of ant macros that have to run in a specific order but with maven it is not possible to invoke the same plugin twice in one and the same phase with preserving the execution order when I need to intercept the two executions by the exectuion of a second plugin.
Assume the following: I have plugin A (native2ascii) and plugin B (replacer). Now my execution order must be A,B,A in just one phase. Sure, I can write it like that but the effective pom would look like A,A,B.
So it would be nice to have a 'proxy-plugin' (P) which would simply invoke the configured plugins. This way you could configure P(A),P(B),P(A) in one phase and the effective pom would be able to preserve the execution order.
Thanks so far!
I've tried out Wim's proposal like in the following but it turned out that the execution ids have no impact on the effective pom. The two executions of the replacer plugin are still combined and run before the native2ascii plugin.
Here is my pom:
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>step-1-replacer</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>src/main/order-test/test.txt</file>
<outputFile>target/test-replaced-1.txt</outputFile>
<replacements>
<replacement>
<token>t</token>
<value>xyz</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>step-2-native2ascii</id>
<phase>generate-sources</phase>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<workDir>target</workDir>
<includes>
<include>test-replaced-1.txt</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>step-3-replacer</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>target/test-replaced-1.txt</file>
<outputFile>target/test-replaced-2.txt</outputFile>
<replacements>
<replacement>
<token>f6</token>
<value>-</value>
</replacement>
<replacement>
<token>e4</token>
<value>></value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And here is how it looks like in the effective pom (both replacer executions are run before the native2ascii execution):
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>step-1-replacer</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>src/main/order-test/test.txt</file>
<outputFile>target/test-replaced-1.txt</outputFile>
<replacements>
<replacement>
<token>t</token>
<value>xyz</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>step-3-replacer</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>target/test-replaced-1.txt</file>
<outputFile>target/test-replaced-2.txt</outputFile>
<replacements>
<replacement>
<token>f6</token>
<value>-</value>
</replacement>
<replacement>
<token>e4</token>
<value>></value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>step-2-native2ascii</id>
<phase>generate-sources</phase>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<workDir>target</workDir>
<includes>
<include>test-replaced-1.txt</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
And here is the output of the build:
...
[INFO] --- replacer:1.5.3:replace (step-1-replacer) # build-order-test ---
[INFO] Replacement run on 1 file.
[INFO]
[INFO] --- replacer:1.5.3:replace (step-3-replacer) # build-order-test ---
[INFO] Replacement run on 1 file.
[INFO]
[INFO] --- native2ascii-maven-plugin:1.0-beta-1:native2ascii (step-2-native2ascii) # build-order-test ---
[INFO] Includes: [test-replaced-1.txt]
[INFO] Excludes: []
[INFO] Processing /home/shillner/work/workspaces/dev/build-order-test/target/test-replaced-1.txt
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Take a look at mojo-executor plugin, it can be used to invoke other plugins - from pom.xml and also programmaticaly.
Example:
<plugin>
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor-maven-plugin</artifactId>
<version>#project.version#</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>execute-mojo</goal>
</goals>
<configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<goal>list</goal>
<configuration>
</configuration>
</configuration>
</execution>
</executions>
</plugin>
There is no official support, but we are using execution ids in alphabetical order and this works fine for many years already.
Example:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>step-0-copy-resources</id>
<goals>
<goal>resources</goal>
</goals>
<phase>package</phase>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>step-1-build-assembly</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/descriptor.xml</descriptor>
</descriptors>
<!-- don't attach assembly to be installed -->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<id>step-2-build-installer</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${basedir}/BuildInstaller.groovy</source>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>step-3-attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/target/project-${project.version}.tar.gz</file>
<type>tar.gz</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Notice how each <id/> starts with "step-x" with x a number.

Resources