2013-04-25 116 views
1

我有兩個項目,A和B,B是一個Web應用程序。項目B依賴於A,因此A公司的ivy.xml看起來像:螞蟻,常春藤,多個項目和傳遞依賴項

<ivy-module version="2.0"> 
    <info organisation="com.confused" module="B" status="integration"/>  

    <dependencies> 
    <!-- confused dependencies --> 
    <dependency name="A" rev="latest.integration"/> 

    <!-- 3rd party dependencies --> 
    <dependency org="org.springframework" name="spring-core" rev="3.2.2.RELEASE"/> 
    <dependency org="org.springframework" name="spring-jdbc" rev="3.2.2.RELEASE"/> 
    <dependency org="org.springframework" name="spring-webmvc" rev="3.2.2.RELEASE"/> 
    </dependencies> 
</ivy-module> 

類似的東西......和我的一個模塊的樣子:

<ivy-module version="2.0"> 
    <info organisation="com.confused" module="A" status="integration"/>  

    <dependencies> 
    <dependency org="org.slf4j" name="slf4j-api" rev="1.7.5"/> 
    <dependency org="ch.qos.logback" name="logback-classic" rev="1.0.11"/> 
    <dependency org="ch.qos.logback" name="logback-core" rev="1.0.11"/> 
    </dependencies> 
</ivy-module> 

都好...除了:

當我建立B,lib目錄與A.jar一起填充彈簧罐。很好,但如果我想'部署'我的webapp,我需要將這些jar複製到WEB-INF/lib以及A依賴的日誌記錄罐中。我如何獲得ant/ivy來「解析」罐子?

回答

2

你沒有把你的依賴關係取決於配置...

有一種非官方的一系列符合了那些在ivy.xml文件中使用Maven的配置,配置的。這ivy.template.xml文件使用它們,我有我的開發人員的基礎上他們的ivy.xml文件。

你需要做的是映射你的配置。這裏有一個的ivy.xml文件:

<ivy-module version="2.0"> 
    <info organisation="com.confused" module="A" status="integration"/>  

    <configurations> 
     <configuration .../> 
     <!-- These are the configurations from the ivy.template.xml file --> 
    </configurations> 

    <dependencies> 
     <dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" 
      conf="compile->default"/> 
     <dependency org="ch.qos.logback" name="logback-classic" rev="1.0.11" 
      conf="compile->default"/> 
     <dependency org="ch.qos.logback" name="logback-core" rev="1.0.11" 
      conf="compile->default"/> 
    </dependencies> 
</ivy-module> 

注意conf映射! compile->default表示使用它來編譯時,以及運行時依賴。通過將其映射到default,您不僅可以下載這個特定的jar文件,還可以下載所有傳遞的依賴文件。

現在,你ivy.xml爲「B」將是這樣的:

<ivy-module version="2.0"> 
    <info organisation="com.confused" module="B" status="integration"/>  

    <configurations> 
     <configuration .../> 
     <!-- These are the configurations from the ivy.template.xml file --> 
    </configurations> 

    <dependencies> 
     <!-- Don't forget the organisation field!--> 
     <dependency org="com.confused" name="A" rev="latest.integration" 
      conf="compile->default"/> 

     <!-- 3rd party dependencies --> 
     <dependency org="org.springframework" name="spring-core" rev="3.2.2.RELEASE" 
      conf="compile->default"/> 
     <dependency org="org.springframework" name="spring-jdbc" rev="3.2.2.RELEASE" 
      conf="compile->default"/> 
     <dependency org="org.springframework" name="spring-webmvc" rev="3.2.2.RELEASE" 
      conf="compile->default"/> 
    </dependencies> 
</ivy-module> 

您的項目的罐子,它的依賴只是只是另一套罐子您的項目「B」取決於起來。

當然,在「B」可以使用之前,您必須將publish A的罐子存入您的常青藤資源庫。

+0

是的,我是一個新手,並沒有完全理解配置。我仍然沒有,但我現在要去弄明白了!然而,我足夠證明你是對的,非常感謝你! – ticktock 2013-04-26 17:20:02

+0

配置是對您的依賴項進行_group_的一種方式。例如,該標準是具有「編譯」配置,「測試」配置和「運行時」配置。你可以使用''創建一個類路徑,這隻包括編譯時需要的jar文件,而不能用於測試或運行時。 d使用類似''。 'a-> b'映射是一種影響行爲的方式,而_standard_ configs與Maven的配置相匹配。 – 2013-04-26 17:30:07