0

Say I have projects A, B, C, and D. B depends on A, C depends on B and D depends on C like so

A <-- B <-- C
      ^
      └ --- D

Is there a way with maven to build C and D given B but to not build A? As in is there a way to build a project and the projects that depend on it?

A, B, C, and D are in a multimodule project. I know I could just build the whole project but that seems like a waste.

Edit: Solution found for this case, in root directory of multimodule project do mvn <your goals here> -pl B -amd, and just for further reference, say B is also a multimodule project and has a, b, and c in it and you want to do with for c, do mvn <your goals here> -pl B\c -amd

Also, is there a way to do this if A and B are in one multimodule project and C and D are in another? I realize that may be trickier.

 platform | us-specific
          |
A <-- B <-+-- C
      ^   |
      └ --+-- D
Captain Man
  • 6,997
  • 6
  • 48
  • 74
  • 1
    possible duplicate of [Maven Modules + Building a Single Specific Module](http://stackoverflow.com/questions/1114026/maven-modules-building-a-single-specific-module) – Joe Apr 16 '15 at 14:41
  • I did find that question but thought it was something else. It did help for **when they are in the same multimodule project** but I am still wondering if there's a way to do it for separate multimodule projects. Thanks though! Editing original post to reflect. – Captain Man Apr 16 '15 at 15:18
  • 1
    I found a way to do this, make a multimodule project with packaging type pom (which essentially is a collection of modules and doesn't actually output anything) that encases the other multimodule projects, in my example that'd be platform and us-specific. It's clunky but works. Leaving unanswered for now in hopes someone has a magic way to do this without a new pom file. – Captain Man Apr 16 '15 at 20:12
  • 1
    Your solution of a multimodule POM that refers to the other projects' top-level modules is exactly how I'd solve the second part of your question -- I'm not aware of another way without manually managing inter-project dependencies. – Joe Apr 17 '15 at 09:47
  • `mvn -r` seems promising, but I am having trouble using it with `-pl`, I don't even know if it's possible. It keeps complaining about same name issues. Wouldn't be a problem if I didn't have two branches of the same code in my workspace, but then again if `-pl` worked with it that wouldn't be an issue (or it's possible I'm getting the syntax of the command wrong, I named the top level folders with a leading dash so they show up in eclipse at the top of the list, but you have to do an escape character like `-pl \-platform` or something). – Captain Man Apr 17 '15 at 14:00

1 Answers1

0

Add a pom file in the folder containing platform and us-specific like so:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>some.group</groupId>
  <artifactId>handyPom</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>platform</module>
    <module>us-specific</module>
  </modules>
  <name>Captain Man's Handy Dandy Pom</name>
</project>

The packaging needs be pom and you need a module for each thing you want to include. The names can change if you want.

As said above you do mvn <your goals here> -pl B -amd.

  • -pl (or --projects) specifies a project list instead of building every project.
    • You can specify subprojects like c in B by doing -pl B\c.
    • It is a list, so more are comma delimited like -pl B\c,C\a to do both B\c and C\a.
    • If for some reason you have a directory with a leading dash (e.g., -foo) you can still use it like -pl \-foo.
  • -amd (or --also-make-dependents) will also build everything that depends on the anything in the list from the full reactor (as in when you don't use -pl <projects>), i.e. their dependents
    • Also, -am (or --also-make) will also build everything the list depends on from the full reactor,. i.e. their dependencies.
    • Reminder about dependencies and dependents, in the question if an arrow implies a dependency to the thing it's pointing to that means
      • A is a dependency of B
      • C and D are dependents of B.
Captain Man
  • 6,997
  • 6
  • 48
  • 74