2

我有两个项目,A 和 B,其中 B 是一个 webapp。项目 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>

类似的东西......我的 A 模块看起来像:

<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 目录中填充了 spring jar 和 A.jar。很好,但是如果我想“部署”我的 web 应用程序,我需要将这些 jar 复制到 WEB-INF/lib 以及 A 所依赖的日志记录 jar 中。我如何让蚂蚁/常春藤也“解决”罐子?

4

1 回答 1

2

您没有放置依赖项所依赖的配置...

有一种非官方的配置集与文件中使用的 Maven 配置相匹配ivy.xml。这个ivy.template.xml文件使用它们,我有它供我的开发人员作为他们ivy.xml文件的基础。

您需要做的是映射您的配置。这是A的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.xmlfor "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>

您的项目 A 的 jar 及其依赖项只是您的项目“B”所依赖的另一组 jar。

当然,您必须先将 A 的 jar发布到您的 Ivy 存储库,然后“B”才能使用它。

于 2013-04-26T05:01:07.817 回答