0

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?

diziaq
  • 6,881
  • 16
  • 54
  • 96
  • Does this answer your question? [Maven Modules + Building a Single Specific Module](https://stackoverflow.com/questions/1114026/maven-modules-building-a-single-specific-module) – Zinc Dec 12 '20 at 10:44
  • @Zinc Thank you for the reference. But that does not approach to the problem, which comes from the unresolved `revision` property. – diziaq Dec 12 '20 at 11:07
  • May be [this one](https://stackoverflow.com/questions/41086512/maven-issue-to-build-one-module-using-revision-property) is your problem. Which version of maven are you using ? – Zinc Dec 12 '20 at 11:14
  • 1
    Does this answer your question? [Maven issue to build one module using revision property](https://stackoverflow.com/questions/41086512/maven-issue-to-build-one-module-using-revision-property) – Brian Tompsett - 汤莱恩 Dec 12 '20 at 11:23
  • @Zinc It's maven 3.6.1+ as described in the minimal example README https://github.com/diziaq/sample-maven-modular-revision – diziaq Dec 12 '20 at 11:26
  • @BrianTompsett-汤莱恩 yes – diziaq Dec 12 '20 at 11:29
  • Very important read the documentation of ci friendlly until the end and add the flatten-maven-plugin which is not part of your pom .... Furthermore your example lacks on parent cause you have one level of directory without a pom file https://github.com/diziaq/sample-maven-modular-revision/tree/main/modules ... which means all the submodules should be moved one level up within directory hierarchy... – khmarbaise Dec 12 '20 at 12:24
  • @khmarbaise Thanks a lot. Yes, `flatten-maven-plugin` is the key. But the directory hierarchy does not affect the problem -- the project can be built with the given structure. The only prerequisite is installing `core` and `base` into local maven repo before calling `package` on `facade`. – diziaq Dec 12 '20 at 12:37
  • If you need to `install` then your build is broken... the directory structure is one of the issues. It would make your handling easier ...Why does have `facade` `base` as parent? and not the one level higher? And configure everything in the root https://github.com/diziaq/sample-maven-modular-revision/blob/main/pom.xml ? You seemed to misunderstand a multi module build.... – khmarbaise Dec 12 '20 at 14:48

1 Answers1

0

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
diziaq
  • 6,881
  • 16
  • 54
  • 96