我有一個多模塊Maven項目,我希望子項目繼承我在父項目中指定的第三方依賴項的版本。這樣我就不需要在任何地方複製版本號。它雖然沒有工作,當我離開了對孩子的版本號我得到的錯誤:如何讓我的子項目在多模塊Maven項目中繼承超級項目的依賴項版本?
dependencies.dependency.version is missing
什麼我需要改變,以得到這個工作?
我有一個多模塊Maven項目,我希望子項目繼承我在父項目中指定的第三方依賴項的版本。這樣我就不需要在任何地方複製版本號。它雖然沒有工作,當我離開了對孩子的版本號我得到的錯誤:如何讓我的子項目在多模塊Maven項目中繼承超級項目的依賴項版本?
dependencies.dependency.version is missing
什麼我需要改變,以得到這個工作?
The <dependencyManagement>
section of the parent POM是爲這個目的:
dependencyManagement
: is used by POMs to help manage dependency information across all of its children. If themy-parent
project usesdependencyManagement
to define a dependency onjunit:junit:4.0
, then POMs inheriting from this one can set their dependency giving thegroupId=junit
andartifactId=junit
only, then Maven will fill in theversion
set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs. In addition, the version and scope of artifacts which are incorporated from transitive dependencies may also be controlled by specifying them in a dependency management section.
不知道OP做究竟是什麼的相關部分,但是這是一個正確的答案:) – 2010-10-10 14:54:42
你有戰爭依賴嗎?
有這可能與你所面臨的問題的一個開放JIRA:
(MNG-2241) Versions are required when it shouldn't with multi-modules projects and war dependencies
我該做的是定義我需要重複作爲父項目的屬性依賴版本。所以:
<properties>
...
<guice.version>2.0</guice.version>
</properties>
然後:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
不是你問什麼了,也許,但它意味着你只需要在一個地方更改版本。
你應該表現出你的pom.xml文件 – 2010-10-10 13:00:26