1

I got a Maven project with the following structure:

Module A (parent), Submodule B and Submodule C

In the parent pom.xml I am using a variable for settings the version of all projects:

...
    <version>${revision}</version>
...
    <properties>
        <revision>1.1</revision>
    </properties>
...
    <modules>
        <module>moduleB</module>
        <module>moduleC</module>
    </modules>
</project>

Module C is my distribution package which uses the shade plugin for packaging everything into one single jar.

In the submodules I set the parent like this:

<parent>
    <groupId>group</groupId>
    <artifactId>moduleA</artifactId>
    <version>${revision}</version>
</parent>

Now I want to use Module C in another project, however I only get the following error when doing so:

Failed to execute goal on project newProject: Could not resolve dependencies for project group:newProject:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at group:moduleC:jar:1.1: Failed to read artifact descriptor for group:moduleC:jar:1.1: Could not find artifact group:parent:pom:${revision} in nexus (NEXUS_URL)

I assume the problem is, that the variable value is not filled in when referencing Module C as dependency. How can I solve this issue? I already tried to clean the project before building and forcing to update all artifacts without success.

mapf
  • 496
  • 1
  • 5
  • 21
  • did you tried to hardcode revision? – Mohsen Dec 07 '18 at 15:57
  • I want to avoid that for easily managing the version of the multi module project at a single spot. In fact, the project has more sub modules than just the two. – mapf Dec 07 '18 at 15:59
  • I just want to know that is working or not – Mohsen Dec 07 '18 at 15:59
  • 1
    I think this link could help you: https://jeanchristophegay.com/maven-unique-version-multi-modules-build-en/ – hadi.mansouri Dec 07 '18 at 16:02
  • I recommend to read the following: https://maven.apache.org/maven-ci-friendly.html (in particular the part about install/deploy)... – khmarbaise Dec 07 '18 at 17:48
  • The flattening stated there was the approach I used. However, this somehow did not work for my distribution module C (see below). – mapf Dec 09 '18 at 09:51

2 Answers2

2

Maven expects all modules to have a hard version.

To avoid editing lots of poms, use the versions plugin, example:

mvn versions:set -DnewVersion=1.0.1

If you run the above command on the parent it will fix all the child poms.

See here for documentation.

Essex Boy
  • 7,565
  • 2
  • 21
  • 24
  • Actually, I used the approach described here: https://stackoverflow.com/questions/10582054/maven-project-version-inheritance-do-i-have-to-specify-the-parent-version/51969067#51969067 Using this approach, Maven does not need a fixed version number anymore. – mapf Dec 07 '18 at 16:37
1

Thanks to the comment of hadu.mansouri I could fix it. I used flatten-maven-plugin for flattening the pom.xml files. However, it seems to have a problem with the shade plugin, as the shaded module was the only module where it did not work. Thus, in the released shade module pom it said:

<version>${revision}</version>

for referencing the parent. I used the approach of the article linked in the comment. There, this extension was used: https://github.com/jcgay/unique-revision-maven-filtering

Using this instead of the flatten-maven-plugin, Maven builds the multi module project correctly with the single version property, and I can also use the shaded module in other projects properly.

mapf
  • 496
  • 1
  • 5
  • 21