Maven - Access properties on parent pom from a child pom

微笑、不失礼 提交于 2019-12-10 22:46:38

问题


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>

回答1:


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.




回答2:


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 (i.e. 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.



来源:https://stackoverflow.com/questions/9708230/maven-access-properties-on-parent-pom-from-a-child-pom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!