1

I have a maven project P that consists of several submodules s1,s2... To make this work, I have the following directory structure:

P
|_pom.xml
|_s1
  |_pom.xml
|_..
|_sN
  |_pom.xml

In the parent pom.xml, I have a normal maven setup:

<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>P</artifactId>
  <version>0.1.0</version>
  <packaging>pom</packaging>
  <name>P</name>
  <modules>
    <module>s1</module>
    <module>s2</module>
    <!-- ... -->
    <module>sN</module>
  </modules>
  <!-- Repos and dependencies go here -->
</project>

And, for each of the child projects, a pom.xml similar to this one:

<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.company</groupId>
    <artifactId>P</artifactId>
    <version>0.1.0</version>
  </parent>
  <groupId>com.company</groupId>
  <artifactId>s1</artifactId>
  <version>0.1.0</version>
  <packaging>jar</packaging>

  <dependencies>
    ...
  </dependencies>
</project>

Additionally, in the project, I have some inter-module dependencies, so for example s4 might require s1 s2 and s5. In order to make this work, I list the submodules as depencencies of other submodules, so for example, in s4's pom.xml I would have:

<dependencies>
  <dependency>
    <groupId>com.company</groupId>
    <artifactId>s1</artifactId>
    <version>0.1.0</version>
  </dependency>
  ...
</dependencies>

The problem with this setup is that, whenever I compile one of the submodule projects, changes in the other submodules are not seen unless they have been previously installed with mvn install. That makes sense, since I'm listing the inter-module dependencies with a specific version, and maven goes to the local repository in the .m2 folder to find them.

Is there a way I can tell maven that I'm in charge of all these projects and that it should recursively go and compile other dependent submodules whenever there are changes?

Setzer22
  • 1,589
  • 2
  • 13
  • 29
  • TL;DR: It can't be done, you must rebuild the parent project, this was not directly answered in the "duplicate" question, so I'll leave this comment for anyone interested. – Setzer22 Jan 25 '17 at 11:22
  • Perhaps not a complete answer to your question, but the `-amd` flag makes maven also build the dependencies of the submodule you're building. If that is insufficient, you could also use the `-pl` (`--projects`) flag to explicitly specify a list of submodules to build like `mvn -pl :s1,:s2,:s5` (notice the colon before the submodule name) – neXus Jul 07 '17 at 12:00

0 Answers0