3

Is there an easier way to force maven to build the parent before the modules ?

Use case: I'm trying to understand what is the best practice to solve the following problem

I have two projects that I will name 'A' and 'B' They both have a parent that I will name 'P'

'P' have a dependency management for shared resources this will allow using the same version for shared artifacts.

'P' is also used to run 'A' and 'B' as modules.

The problem: When a new artifact is added I'm adding the version in 'P' and the dependency at 'A' (for example). now when doing a maven clean install I'm getting 'dependencies.dependency.version' is missing for .

This is due to the fact that maven first builds it's modules before himself and then 'A' doesn't have the version.

I know that I can put in 'A' pom under the following: ../ and it works (but no always).

Back to my question: is there an easier way to force maven to build the parent before the modules ?

Ika
  • 1,456
  • 1
  • 15
  • 24

2 Answers2

1

I found that my problem was not only the relative path as mentioned above but the fact that my parent pom version was a variable ${version} and was not replaced during build.

To solve this issue I hard coded wrote the parent version in the parent POM.

Ika
  • 1,456
  • 1
  • 15
  • 24
0

In your case, that is the situation where modules' parent == modules' aggregator, Maven should build parents before their modules as long as they're in the same build reactor and that usually means you should build all modules from the P project level. And even if you don't, parents should be resolved right if your have proper <relativePath> tags in your <parent> blocks within modules' pom.xml (look here for example). By default there is .. value there which means that artifact's parent is in the parent directory in filesystem.

Michał Kalinowski
  • 16,925
  • 5
  • 35
  • 48