繁体   English   中英

有条件地排除常春藤依赖

[英]Excluding an Ivy dependency conditionally

我需要构建一个自定义的Ant脚本,该脚本可以基于CI输出构建一个项目。 我们使用Atlassian Bamboo作为CI服务器。

通常,我们的项目依赖于我们的平台模块,并通过Ivy / Artifactory管理。

我们典型的dependencies.xml文件可传递地包含对该模块的依赖。 其他潜在的依赖关系。 例如,我们的核心模块依赖于许多Spring软件包,而不依赖于Spring Boot。 如果一个项目也需要Spring Boot,它将在其dependencies.xml文件中定义其依赖关系,以及<depencency org="com.acme" name="core-platform"...

我现在的目标是将com.acme#core-platform排除在分辨率之外,因为我正在执行另一项任务,该任务使用Bamboo输出工件来获取核心模块及其依赖项的最新版本,而无需经过Artifactory。

这一点非常重要,因为在构建过程中,我可能希望更改相关软件包的版本(例如,将Spring 4.3.1升级到4.3.3)并使用正确的Spring进行测试。 如果仅将依赖关系解析为在Artifactory上发布的com.acme#core-platform#latest.release ,则不会采用Spring的4.3.3版本,该版本致力于Git,并且可以在core-platform当前构建的版本中使用dependencies.xml 我希望我的解释容易理解。

所以说我有这个依赖列表作为例子

    com.acme#core-platform#${version}
    org.hibernate#hibernate-java8#5.1.0.Final
    org.springframework.boot#spring-boot-starter-web#1.3.1.RELEASE
    commons-collections#commons-collections#3.2.2
    .... others

完全依赖为

<dependencies>  
    <dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="runtime->runtime" changing="true"/>
    <dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="compile->compile" changing="true"/>
    <dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="provided->provided" changing="true"/>
    <dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="junit->junit" changing="true"/>
    <dependency org="com.acme"              name="core-platform"          rev="${version}"         transitive="true"      conf="test->test" changing="true"/>



    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-java8 -->
    <dependency org="org.hibernate" name="hibernate-java8" rev="5.1.0.Final" transitive="false" />


    <dependency org="org.springframework.boot"  name="spring-boot-starter-web"          rev="1.3.1.RELEASE"                 transitive="false" />
    <dependency org="org.springframework.boot"  name="spring-boot-starter-tomcat"       rev="1.3.1.RELEASE"                 transitive="false" />
    <dependency org="org.springframework.boot"  name="spring-boot-starter-validation"   rev="1.3.1.RELEASE"                 transitive="false" />


    <dependency org="commons-collections"               name="commons-collections"              rev="3.2.2"             transitive="false" />


    <!-- jackson2 libs -->
    <dependency org="com.fasterxml.jackson.datatype"    name="jackson-datatype-jdk8"            rev="2.8.1"             transitive="false"          conf="runtime->*"/>
    <dependency org="com.fasterxml.jackson.datatype"    name="jackson-datatype-jsr310"          rev="2.8.1"             transitive="false"          conf="runtime->*"/>


    <exclude module="joda-time" />
    <exclude module="jackson-datatype-joda" />
</dependencies>

我只是想使用Hibernate的Java8,commons-collections等。

  1. 创建重复的dependencies.xml 不是一种选择
  2. 我正在考虑通过Ant来操作dependencies.xml,并使其通过正则表达式排除acme模块。 可行但棘手
  3. 不幸的是,我无法将Ant任务的ivy:retrieve与属性file和元素exclude ,因为那样可以帮助looooooot

有任何想法吗?

很难理解您的要求。 我怀疑可以通过创建其他配置并使用配置映射来控制下载来解决您的问题。

此生成将创建两个目录。 第一个包含没有传递依赖的log4j依赖,第二个包含远程模块的可选依赖。 如果查看远程POM,您会发现它们具有不同的范围。

├── build.xml
├── ivy.xml
├── lib1
│   └── log4j-1.2.17.jar
└── lib2
    ├── activation-1.1.jar
    ├── geronimo-jms_1.1_spec-1.0.jar
    ├── log4j-1.2.17.jar
    └── mail-1.4.3.jar

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

  <target name="resolve">
    <ivy:resolve/>

    <ivy:retrieve pattern="lib1/[artifact]-[revision](-[classifier]).[ext]" conf="noDependencies"/>
    <ivy:retrieve pattern="lib2/[artifact]-[revision](-[classifier]).[ext]" conf="withDependencies"/>
  </target>

</project>

笔记:

  • 每个“检索”任务都会创建一个目录,其中包含构成配置的文件。

常春藤

<ivy-module version="2.0">
  <info organisation="com.myspotontheweb" module="demo"/>

  <configurations>
    <conf name="noDependencies" description="File grouping that has no transitive dependencies"/>
    <conf name="withDependencies" description="File grouping that contains dependencies"/>
  </configurations>

  <dependencies>
    <dependency org="log4j" name="log4j" rev="1.2.17" conf="noDependencies->master; withDependencies->master,optional"/>
  </dependencies>

</ivy-module>

笔记:

  • 请注意,如何在ivy文件顶部声明配置,并且依赖项包含两个配置映射

额外

以下答案说明了ivy如何解释Maven模块。 它创建可用于决定应下载哪些文件的配置:

好的,看起来替换技巧也很容易。

  1. <!-- DEPS START -->文件的各部分之间添加以下标记<!-- DEPS START --><!-- DEPS END --> (或选择任意一种)
  2. 通过蚂蚁入侵

     <copy file="dependencies.xml" tofile="ci/hacked-dependencies.xml" overwrite="true"> <filterchain> <replacestring from="&lt;!-- DEPS START --&gt;" to="&lt;!--" /> <replacestring from="&lt;!-- DEPS END --&gt;" to="--&gt;" /> </filterchain> </copy> 

    <!-- DEPS START --> 
    <dependency org="com.acme" name="core-platfrom" rev="${version}" transitive="true" conf="runtime->runtime"/>
    <!-- DEPS END -->

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM