Following maven-ci-friendly article in official Maven documentation, this multimodule project (minimal example) was created.
There are three modules and a root project (inception):
/inception
/modules
/base (common parent of 'core' and 'facade')
/core (child of 'base')
/facade (child of 'base' having 'core' as a dependency)
Executing mvn package
from inception
works as expected - all 3 *.jar
artifacts are being created in the corresponding target
forlders.
I would like to have an option of building facade
module separately.
Unfortunately, mvn package
from modules/facade
fails to collect dependencies and fails with error
[ERROR] Failed to execute goal on project sample-facade:
Could not resolve dependencies for project sample.group:sample-facade:jar:0.0.1:
Failed to collect dependencies at sample.group:sample-core:jar:0.0.1:
Failed to read artifact descriptor for sample.group:sample-core:jar:0.0.1:
Could not transfer artifact sample.group:sample-base:pom:${revision}
The surface problem is that ${revision}
is not being resolved into 0.0.1
.
Could you help me workaround this issue?
The flatten-maven-plugin
solves the problem.
Thanks to @khmarbaise, who adviced in the comments reading the docs to the end.
Adding the plugin to /modules/base/pom.xml
solved the problem with building a submodule separately:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.5</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
Before starting a phase on facade
module, it is required to have base
and core
in the local repository, so maven could find the artifacts. Hence, here is the sequence of actions in root:
mvn install -pl modules/base,modules/core
(or just mvn install
)mvn package -pl modules/facade