0

Borrowing example from a similar question, I have two projects: Parent project: A, Sub project: B

in A/pom.xml:

<groupId>com.dummy.bla</groupId>
<artifactId>parent</artifactId>
<version>2.0</version>
<packaging>pom</packaging>

in B/pom.xml, I have:

<parent>
    <groupId>com.dummy.bla</groupId>
    <artifactId>parent</artifactId>
    <version>2.0</version>     
</parent>

<groupId>com.dummy.bla.sub</groupId>
<artifactId>kid</artifactId>

I run tests on B as follows,

mvn test -pl B

Is it possible to override parent version, like following?

mvn test -pl B -Dparent=1.0
Community
  • 1
  • 1
Indrajeet
  • 521
  • 3
  • 9
  • 23

1 Answers1

0

You parent project version have then to be dynamic using a maven property which you can then override with a system one.

All you child modules have to inherit the parent version and should not define theirs or all the process down will be broken.

Update your parent poject descriptor to be as below:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.dummy.bla</groupId>
  <artifactId>parent</artifactId>
  <version>${project.custom.version}</version> <!-- Dynamic project version which defaults to 2.0 -->
  <packaging>pom</packaging>

  <name>parent</name>

  <properties>
    <project.custom.version>2.0</project.custom.version>
  </properties>

  <modules>
    <module>kid</module>
  </modules>
  <!-- ... -->
</project>

Then declare you parent poject in submodules using the same dynamic version:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.dummy.bla</groupId>
    <artifactId>parent</artifactId>
    <version>${project.custom.version}</version>
  </parent>
  <artifactId>kid</artifactId>
  <name>kid</name>
  <!-- ... -->
</project>

The command line invocation then will do the trick using either the version declare or the default one:

~ cd parent/
~ mvn -pl kid -Dproject.custom.version=3.1
tmarwen
  • 15,750
  • 5
  • 43
  • 62