Maven - attach artifact with Maven descriptor files - maven

For performance reasons I need to create a new EAR artifact beside a WAR archive without using multiple modules projekt. The EAR will contain the WAR (in the /web sub-directory) and the static application.xml file.
All I need to generate in the non-static way is Java classes and Maven descriptor files (META-INF/maven/${groupId}/${artifactId}/pom.xml and META-INF/maven/${groupId}/${artifactId}/pom.properties).
With classes there is no big deal, but how to generate and attach the Maven descriptor files to the new EAR?
This works well, but the Maven descriptor files are not generated inside the EAR archive.
...
<packaging>war</packaging>
...
<properties>
<compile.dir>${project.build.directory}/${project.build.finalName}</compile.dir>
<ear.zip>${project.build.directory}/my-archive.ear</ear.zip>
</properties>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-EAR-archive</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- copy webapp files -->
<copy todir="${compile.dir}/web">
<fileset dir="src/main/webapp" />
</copy>
<!-- copy classes -->
<copy todir="${compile.dir}/web/WEB-INF/classes">
<fileset dir="${project.build.directory}/classes" />
</copy>
<!-- copy application.xml -->
<copy todir="${compile.dir}">
<fileset dir="src/main/resources" includes="META-INF/application.xml" />
</copy>
<!-- copy some big files -->
...
<!-- zip EAR -->
<zip destfile="${ear.zip}" basedir="${compile.dir}" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>attach-EAR-artifact</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<phase>package</phase>
<configuration>
<artifacts>
<artifact>
<file>${ear.zip}</file>
<type>ear</type>
<classifier>exploded</classifier>
</artifact>
</artifacts>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

The easiest thing is to have a multi module project.
A parent 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<myproject.version>1.0-SNAPSHOT</myproject.version>
</properties>
<name>ear-example</name>
<modules>
<module>example-ear</module>
<module>example-war</module>
</modules>
</project>
A war as you have, and an ear project:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>example-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>com.greg</groupId>
<artifactId>example-jar</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then just add any files you need to the src/main/application directory in the ear project and they will appear in the top level of your ear file.
See http://maven.apache.org/plugins/maven-ear-plugin/usage.html

The solution is to move the war package phase into another phase before the prepare-package phase, then there is a complete WAR archive containing the maven descriptor files. So it means, all the data are ready when the EAR archive is prepared.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
The archive unzip and use in the prepare-package phase as before:
<!-- unzip the war -->
<unzip src="${project.build.directory}/${project.build.finalName}.war" dest="${project.build.directory}/war-exploded" />
<!-- move the war content -->
<move todir="${compile.dir}/web">
<fileset dir="${project.build.directory}/war-exploded" />
</move>

Related

Defining plugin goal at phase

I am trying to define a plugin goal so that it can automatically be executed at a particular phase; say for example the test phase. But I am unable to achieve that. For example I coded the following pom.xml. Notice in my XML <execution> element, I have a <phase> sub-element which is "test". I can execute my goal using the command "mvn antrun:run#ant-echo"; but "mvn test" does not execute that goal. I am using Maven version 3.8.3 and my JDK version is 16.
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run#ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
In order to have your plugin executed during the configured lifecycle phase, you have to specify the plugin goal binding and configuration within the <plugin> section:
<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>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run#ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

How to build p2 repository with p2-maven-plugin and use local directory as a source of JARs?

Situation: Eclipse RCP application using Maven Tycho plugin, now I want to integrate properly p2-maven-plugin`. I have a directory containing all 3rd party JARs and Eclipse plugins as JARs.
How to use p2-maven-plugin to create p2 repository which includes all files from this directory?
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>p2-site</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>default-cli</id>
<!-- How can I get there artifacts located in directory on my local machine??? These libs (in example below) are taken from .m2 maven repo -->
<configuration>
<artifacts>
<artifact>
<id>commons-lang:commons-lang:2.4</id>
</artifact>
<artifact>
<id>commons-lang:commons-lang:2.5</id>
</artifact>
<artifact>
<id>commons-lang:commons-lang:2.6</id>
</artifact>
<artifact>
<id>junit:junit:3.8.2</id>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>${project.basedir}/target/repository/</webAppSourceDirectory>
<webApp>
<contextPath>/site</contextPath>
</webApp>
<stopKey/>
<stopPort/>
</configuration>
</plugin>
</plugins>
</build>
...
Thanks!
EDIT:
Folder with plugins (JARs) from which I want to generate p2 repository.
usage of tycho extras p2 plugin in my master pom - doesn't work, I think maybe this piece of code is not called at all... How can I it call?

maven Return code is: 409, ReasonPhrase: Conflict

I have problem to deploy my multi-module python project with following structure
parent pom.xml # common pom for others project
project/
pom.xml # project pom
common_features/
sub-project-1/pom.xml # sub project 1 pom
sub-project-2/pom.xml # sub project 2 pom
For deployment I use maven
Settings.xml
General maven setting use for build
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- others options -->
<servers>
<server>
<id>artifacts-SNAPSHOTS</id>
<username>user</username>
<password>password</password>
</server>
</servers>
<!-- others options -->
</settings>
parent pom.xml
In this case we have the same URL for SNAPSHOT and RELEASE repository
<!-- others options -->
<groupId>com.project.common.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<!-- others options -->
<distributionManagement>
<repository>
<id>artifacts-RELEASES</id>
<url>${dist.repository.releases}</url>
</repository>
<snapshotRepository>
<id>artifacts-SNAPSHOTS</id>
<url>${dist.repository.snapshots}</url>
</snapshotRepository>
</distributionManagement>
<!-- others sections-->
<properties>
<dist.repository.releases>${artifacts.repository.url}</dist.repository.releases>
<dist.repository.snapshots>${artifacts.repository.url}</dist.repository.snapshots>
<artifacts.repository.url>https://domain/artifactory/mvn-repo-dev</artifacts.repository.url>
</properties>
project pom.xml
There you can see that project consists two modules
sub-project-1
sub-project-2
Parent is general parent.
Also I sue maven assembly plugin in order to deploy project into artifactory
<!-- anothers options -->
<parent>
<groupId>com.project.common.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.project.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>common_features/sub-project-1</module>
<module>common_features/sub-project-2</module>
</modules>
build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>deploy/artifact-description.xml</descriptor>
</descriptors>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
<executions>
<execution>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.6.1</version>
<inherited>false</inherited>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<publisher>
<contextUrl>https://domain/artifactory</contextUrl>
<repoKey>mvn-repo-dev</repoKey>
<snapshotRepoKey>mvn-repo-dev</snapshotRepoKey>
<publishArtifacts>true</publishArtifacts>
<publishBuildInfo>true</publishBuildInfo>
<username>deployUser</username>
<password>deployPwd</password>
</publisher>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
artifact-description.xml
I want to deploy only some section therefore I define the following deployment file. With this I ensure that into package will be deploy only common features and project specific scripts/codes
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>${distributionId}</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>project/${subProjectName}/</outputDirectory>
<directory>${basedir}/..</directory>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
<includes>
<include>/*.*</include>
<include>/sub-${subProjectName}/*</include>
</includes>
<excludes>
<exclude>**/*.pyc</exclude>
<exclude>**/*.xls</exclude>
<exclude>**/*.xlsx</exclude>
<exclude>**/pom.xml</exclude>
<exclude>**/target</exclude>
<exclude>**/deploy</exclude>
<exclude>**/.venv</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
sub-project-1 pom.xml
This is only simple pom without others plugins and build options
<parent>
<groupId>com.project.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
<groupId>com.project.group.id</groupId>
<artifactId>sub-project-1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<subProjectName>project-1</subProjectName>
</properties>
sub-project-2 pom.xml
The same pom.xml as for sub-project-1
<parent>
<groupId>com.project.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
<groupId>com.project.group.id</groupId>
<artifactId>sub-project-2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<subProjectName>project-2</subProjectName>
</properties>
Now I want to build and upload only sub-project-1 it into artifactory and therefore I will use the following maven command:
mvn -e -B -U -X clean deploy --projects :sub-project-1 -DskipIntegrationTests=false -DskipCoverageReport=false
But then following error occur:
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: https://domain/artifactory/mvn-repo-dev/com/project/group/id/project/project-1/1.0.0-SNAPSHOT/sub-project-1-1.0.0-20190723.081454-1.pom. Return code is: 409, ReasonPhrase: Conflict.
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:627)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:541)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:523)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:517)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:497)
at org.eclipse.aether.transport.wagon.WagonTransporter$PutTaskRunner.run(WagonTransporter.java:644)
at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
at org.eclipse.aether.transport.wagon.WagonTransporter.put(WagonTransporter.java:410)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PutTaskRunner.runTask(BasicRepositoryConnector.java:510)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
... 32 more
Now I am not sure what is wrong and I spend a lot of hours of investigation this issue but nothing found. Please do you have some suggestions what is wrong here? Thanks a lot
I found where is the problem. Within parent pom.xml there was the following plugin which change artifactId. I do not know why I got error 409 but finally this was a reason:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>pre-clean</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.getModel().setArtifactId(project.properties["someProperty"].replaceAll('_',
'-'))
project.getArtifact().setArtifactId(project.properties["someProperty"].replaceAll('_',
'-'))
</source>
</configuration>
</execution>
</executions>
</plugin>

maven build ear - how I can build just a .ear file and not the exploded ear dir?

I just need a myEar.ear file as output of my maven build.
I don't want the dir myEar (the exploded ear version).
To be clear, this is my build output:
20/02/2017 11:37 <DIR> myEar
20/02/2017 11:37 7.985.535 myEar.ear
I just want the myEar.ear.
Thanks.
Here my pom.xml of the ear:
<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>
<name>myEar</name>
<description>myEar</description>
<groupId>com.foo</groupId>
<artifactId>myEar</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<parent>
</parent>
<properties>
</properties>
<dependencies>
(...)
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.foo</groupId>
<artifactId>myWeb</artifactId>
<contextRoot>/myWeb</contextRoot>
</webModule>
<webModule>
<groupId>com.foo</groupId>
<artifactId>myWS</artifactId>
<contextRoot>/</contextRoot>
</webModule>
</modules>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
<directory>${basedir}/../target/diraliases/EARHOMEDIR1036</directory>
<finalName>myEar</finalName>
</build>
</project>
I fixed with th maven-antrun-plugin... an ant call inside maven... very dirty... someone has a better idea?
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>deleteDir</id>
<phase>package</phase>
<configuration>
<tasks>
<delete dir="${basedir}/../target/diraliases/EARHOMEDIR1036/myEar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

How to share a filtered resource at generate-sources phase in a multi module project?

I have a parent project with 3 child projects:
parent
project-1
/src/main/resources/config.xml
project-2
/src/main/resources/config.xml
project-3
/src/main/resources/config.xml
The configuration config.xml is used during the generate-sources phase. For the three projects, the config.xml is exactly the same. However, the usage of this config.xml is different for each project.
In project-X, I am referring to config.xml as following:
<build>
<plugins>
<plugin>
<groupId>some-group</groupId>
<artifactId>some-artifact</artifactId>
<executions>
<execution>
<goals>
<goal>some-goal</goal>
</goals>
<configuration>
<input>src/main/resources/config.xml</input>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
What is the best way to share this common config.xml between all 3 projects?
You can use the build-helper-maven-plugin here.
PROJECT STRUCTURE
shared-resources-project
+-src
+-main
+-resources
`config.xml
+-project-A
`pom.xml
+-project-B
`pom.xml
+-project-C
`pom.xml
`pom.xml
shared-resources-project/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my</groupId>
<artifactId>shared-resources-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>project-A</module>
<module>project-B</module>
<module>project-C</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-sources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.parent.basedir}/src/main/resources</directory>
<includes>
<include>config.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>some-group</groupId>
<artifactId>some-artifact</artifactId>
<executions>
<execution>
<id>some-plugin-job</id>
<phase>generate-sources</phase>
<goals>
<goal>some-goal</goal>
</goals>
<configuration>
<input>${project.build.outputDirectory}/config.xml</input>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
shared-resources-project/src/main/resources/config.xml
<config>
<parameter>${custom-value}</parameter>
</config>
project-X/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my</groupId>
<artifactId>shared-resources-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>project-X</artifactId>
<properties>
<custom-value>Project-X Value</custom-value>
</properties>
</project>
Now, let's build the project:
D:\workspaces> cd shared-resources-project
D:\workspaces\java\shared-resources-project> mvn clean install
Some notes:
The build-helper-maven-plugin will add the common config.xml file as a resource to Project-X.
Then the Maven resources plugin (MRP) will copy config.xml to the project output directory (target directory by default). During the copy, MRP will also replace ${custom-value} with the specific value provided by Project-X.
The final config.xml will be available to another plugin as long as the other plugin is bound to the generate-source phase AND its declaration appears AFTER the build-helper-maven-plugin declaration. Maven (3.0.4+ at least) calls the plugins in their order of apparition in the pom.xml.

Resources