java 如何访问maven多模块项目中其他模块pom中定义的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25499579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to access properties defined in other module pom in maven multimodule project
提问by HimanshuR
In pom of A.B.C i have defined a property as abc where A B C are modules. Now i want to access that property in pom of A.D.F module.
在 ABC 的 pom 中,我将一个属性定义为 abc,其中 ABC 是模块。现在我想在 ADF 模块的 pom 中访问该属性。
<properties>
<A.B.C>${buildNumber}</A.B.C>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>buildnumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<timestampFormat>{0,date,dd-MM-yyyy HH:mm:ss}</timestampFormat>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
<revisiononscmfailure>
<!-- 71 Generate sequence build number based on: 72 build number and
timestamp 73 -->
<format>Build: #{0} ({1,date})</format>
<items>
<item>buildNumber\d*</item>
<item>timestamp</item>
</items>
</revisiononscmfailure>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.maven-scm-provider-svnjava</groupId>
<artifactId>maven-scm-provider-svnjava</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.8.5</version>
</dependency>
</dependencies>
</plugin>
I am using ${A.B.C} as value of version in a dependency in A.D.F module's pom.
我在 ADF 模块的 pom.xml 中的依赖项中使用 ${ABC} 作为版本的值。
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version>${A.B.C}</version>
<type>bundle</type>
</dependency>
So it is giving me error: bundle must be a valid version but is ${A.B.C}.
所以它给了我错误:bundle 必须是一个有效的版本,但它是 ${ABC}。
EDIT:
编辑:
or can i use version of C module in someway as i have defined:
或者我可以按照我定义的方式使用 C 模块的版本:
<version>${A.B.C}</version>
采纳答案by HimanshuR
Explanation provided in answer of this question explains it in a very good manner that what can be used and when.
在回答这个问题时提供的解释很好地解释了可以使用什么以及何时使用。
回答by coffeeaddict
Do those modules share a parent pom? Seems like if you want them linked, it would be a good idea to have them share properties via parent, especially if you want to tightly couple module versions between many modules.
这些模块是否共享父 pom?似乎如果您希望它们链接起来,让它们通过父级共享属性是个好主意,尤其是如果您想在许多模块之间紧密耦合模块版本。