2013-04-25 119 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