2010-10-10 95 views
7

我有一個多模塊Maven項目,我希望子項目繼承我在父項目中指定的第三方依賴項的版本。這樣我就不需要在任何地方複製版本號。它雖然沒有工作,當我離開了對孩子的版本號我得到的錯誤:如何讓我的子項目在多模塊Maven項目中繼承超級項目的依賴項版本?

dependencies.dependency.version is missing 

什麼我需要改變,以得到這個工作?

+0

你應該表現出你的pom.xml文件 – 2010-10-10 13:00:26

回答

11

The <dependencyManagement> section of the parent POM是爲這個目的:

dependencyManagement : is used by POMs to help manage dependency information across all of its children. If the my-parent project uses dependencyManagement to define a dependency on junit:junit:4.0 , then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version 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.

+0

不知道OP做究竟是什麼的相關部分,但是這是一個正確的答案:) – 2010-10-10 14:54:42

0

我該做的是定義我需要重複作爲父項目的屬性依賴版本。所以:

<properties> 
    ... 
    <guice.version>2.0</guice.version> 
</properties> 

然後:

<dependency> 
    <groupId>com.google.inject</groupId> 
    <artifactId>guice</artifactId> 
    <version>${guice.version}</version> 
</dependency> 

不是你問什麼了,也許,但它意味着你只需要在一個地方更改版本。

相關問題