简体   繁体   中英

Maven - Access properties on parent pom from a child pom

In a multi module project structure as

myApp
|-moduleA
|---pom.xml
|-moduleB
|---pom.xml
|-pom.xml

If i have the following properties in the parent.pom

  <properties>
   <moduleA.version>4.67</moduleA.version>
   <moduleB.version>4.68</moduleB.version>
  </properties>  

How can i access the properties in the parent pom from any of the child poms? I tried this on the child pom but it didnt work.

  <groupId>com.test</groupId>
  <artifactId>moduleA</artifactId>
  <version>${moduleA.version}</version>

If you have a real multi-module build you should never define the modules to have different versions. They should have the same version which make releasing possible and other things as well. Otherwise you should not use the multi-module setup than use simple single modules which are separated.

This should work. One possible reason I can think of is that perhaps you don't actually inherit the pom where these properties are defined (ie it's not defined as your <parent> directly or indirectly), but you only have a main pom that aggregates your projects. It's a guess, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM