[英]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等。
acme
模块。 可行但棘手 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
<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如何解释Maven模块。 它创建可用于决定应下载哪些文件的配置:
好的,看起来替换技巧也很容易。
<!-- DEPS START -->
文件的各部分之间添加以下标记<!-- DEPS START -->
和<!-- DEPS END -->
(或选择任意一种) 通过蚂蚁入侵
<copy file="dependencies.xml" tofile="ci/hacked-dependencies.xml" overwrite="true"> <filterchain> <replacestring from="<!-- DEPS START -->" to="<!--" /> <replacestring from="<!-- DEPS END -->" to="-->" /> </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.