[英]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.