3

Since system scope is said to be deprecated and dangerous, we use a local repository. The repository is in the parent folder and used by most of the submodules. Now including the repo gets messy. Providing the URL is sort of a hack.

We tried ${project.parent.basedir}/repo in the submodules, but this evaluates to nothing. We also tried to set it in the parent pom, ...

<repository>
  <id>project_repo</id>
  <url>file://${project.basedir}/project_repo</url>
</repository>

but maven decides to ship the url as given to the submodules which in turn evaluate the property. This lead us to the mess of just taking the relative parent dir, forcing the submodules to be subfolders of the parent pom:

<url>file://${project.basedir}/../project_repo</url>

This is problem Y. The question concerning X is, why does maven inherit before evaluation and how can I avoid this?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
  • 1
    What is the purpose of this file based repository which is in general a bad idea...either use the local cache `$HOME/.m2/repository` and it's good idea to use a repository manager... – khmarbaise Jun 06 '16 at 13:25
  • You missunderstood the purpose of the project_repo. It is a repo equivalent to the central maven repo, not the local cache in `.m2`. The purpose is to hold 3rd party JARs, which you need but don't exist in any public repository. It supersedes the (discouraged) use of the system scope. – ManuelSchneid3r Jun 06 '16 at 15:04
  • Yes i know but it does not make sense anyway. You should use a repository manager and handle it there...so you get rid of such hacks... – khmarbaise Jun 06 '16 at 15:37
  • Did you manage to solve this? I'm having exactly the same problem. – lpacheco Feb 17 '17 at 18:09

1 Answers1

4

forcing the submodules to be subfolders of the parent pom

Regardless of other faced issue, this is actually the recommended approach in general, to have a multi-module/aggregation project (the parent) and submodules as subfolders, in order to have one central/entry-point folder (the parent) providing common configuration and governance (its pom.xml file) and modules (subfolders).

but maven decides to ship the url as given to the submodules which in turn evaluate the property.

Indeed project.basedir is evaluated as the folder containing the pom.xml against we are currently building (or sub-building, in case of a module), since the building project is the module at a given time.
From official documentation concerning project.basedir

The directory that the current project resides in.

If you want to always point to the folder from which you launched your build (that is, the aggregator/parent project in this case), you could use session.executionRootDirectory instead.

However, be careful especially if wishing to build a module directly from its directory, you may then run into troubles (path issues): you should always run it from the parent using reactor options like -pl (projects to build).

This is also a trigger for further thoughts: maintenance and readability of the project may suffer this approach. An enterprise Maven repository would then be a better solution.


Further reading on SO:


Update

The question concerning X is, why does maven inherit before evaluation and how can I avoid this?

Concerning your X question, here is the explanation I could find:

The answer relies in the core of a Maven build, the Maven Model Builder:

The effective model builder, with profile activation, inheritance, interpolation, ...

In particular, it performs the following steps in the following order:

  • phase 1
    • profile activation
    • raw model validation
    • model normalization
    • profile injection
    • parent resolution until super-pom
    • inheritance assembly
    • model interpolation
    • url normalization

Bold is mine. That is, it does so because it's made to do so by its model.

Community
  • 1
  • 1
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • hi @A_Di-Matteo , can u pls have a look at this - https://stackoverflow.com/questions/55530477/maven-pom-inheritance-ands-overriding-in-parent-child-module – Number945 Dec 05 '19 at 08:58