Java ivy:retrieve选择要使用的ivy.xml文件
在调用Java ivy:retrieve选择要使用的ivy.xml文件,java,ant,ivy,Java,Ant,Ivy,在调用ivy:retrieve时,是否有方法选择要使用的ivy.xml文件 看起来,我似乎可以使用settingsRef属性来选择要使用的常春藤设置文件,但我要修改的不是ivysettings.xml文件,而是IVY.xml。我的用例如下所示: 我有一个主ivy.xml文件,用于获取编译时和运行时依赖项 我还拥有许多构建工具链依赖项,即某些Ant任务本身使用的JAR(例如findbugs、cobertura、pmd、代码样式符合性检查等)。这些东西既不是我的代码的编译时依赖性,也不是我的代码的
ivy:retrieve
时,是否有方法选择要使用的ivy.xml
文件
看起来,我似乎可以使用settingsRef
属性来选择要使用的常春藤设置文件,但我要修改的不是ivysettings.xml
文件,而是IVY.xml
。我的用例如下所示:
- 我有一个主
文件,用于获取编译时和运行时依赖项ivy.xml
- 我还拥有许多构建工具链依赖项,即某些Ant任务本身使用的JAR(例如findbugs、cobertura、pmd、代码样式符合性检查等)。这些东西既不是我的代码的编译时依赖性,也不是我的代码的运行时依赖性。此外,我用这个工具链构建的所有项目都是一样的,所以我希望能够在一个单独的
文件中识别这些依赖关系,我可以简单地在我的项目中复制ivy.xml
file
。his的原因是检索是一个。短答案是使用常春藤配置:
Ivy配置可用于为不同目的对依赖项进行分组。您不需要多个常春藤文件
例子
以下是我的决心目标:
<target name="resolve" description="Download dependencies and setup classpaths">
<ivy:resolve/>
<ivy:report todir='${reports.dir}/ivy' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
<ivy:cachepath pathid="build.path" conf="build"/>
</target>
然后可以直接在需要类路径的各种任务中使用
<!-- Compiling code -->
<javac srcdir="${src.dir}"... classpathref="compile.path"/>
<!-- Testing code -->
<junit haltonfailure="yes" fork="true">
<classpath>
<path refid="test.path"/>
<pathelement path="${classes.dir}"/>
<pathelement path="${test.classes.dir}"/>
</classpath>
..
</junit>
<!-- 3rd party ANT tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpathref="build.path"/>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="build.path"/>
..
..
..
就我个人而言,我只使用检索任务来建立档案。在这里,我再次使用配置来控制我想要的jar:
<ivy:retrieve pattern="${build.dir}/libs/[artifact].[ext]" conf="runtime"/>
<war destfile="${war.file}" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<classes dir="${build.dir}/classes"/>
<lib dir="${build.dir}/libs"/>
</war>
常春藤锉
所需的配置在顶部声明。请注意有些操作是如何设置的。例如,“编译”依赖项自动成为“运行时”和“测试”的一部分
其次,配置映射至关重要:
- myconf->default:包括可传递的依赖项
- myconf->master:只有模块jar,没有依赖项
<target name="fetch-buildsystem-deps" depends="configure-ivy-settings">
<ivy:resolve file="ivy-buildsystem.xml"/>
<ivy:retrieve conf="build-system"
pattern="${lib-ivy-buildsystem.dir}/[artifact]-[revision](-[classifier]).[ext]"
sync="true"
type="jar, bundle"/>
</target>
向上投票。然而,我知道采用不同配置的可能性。我特别要求使用单独的IVY文件,因为我希望在多个项目中具有相同的“ANT任务依赖性”,并且使用单独的IVY文件可以很容易地检查(使用diff甚至符号链接),而使用您的解决方案,您必须目视检查文件,以确保“ANT任务依赖性”确实是一样的(当然,这对你很重要)。我相信我已经做到了,但是在我发布我自己的答案之前,我很乐意接受你的答案,因为这是一篇很棒的文章。顺便说一句,我不喜欢使用
ivy:cachepath
,因为它对于实际包含的罐子有点不透明。我使用ivy:retrieve
,即使是“ANT任务依赖项”,因为我希望能够检查文件系统上的目录并查看引入的所有JARivy:cachepath
据我所知不提供这种可视性。@MarcusJuniusBrutus注意到我的“resolve”目标如何使用ivy“report”任务生成每个配置上JAR的详细报告。
<target name="fetch-buildsystem-deps" depends="configure-ivy-settings">
<ivy:resolve file="ivy-buildsystem.xml"/>
<ivy:retrieve conf="build-system"
pattern="${lib-ivy-buildsystem.dir}/[artifact]-[revision](-[classifier]).[ext]"
sync="true"
type="jar, bundle"/>
</target>
<configurations>
<conf name="build-system" description="artifacts needed by the build-system itself"/>
</configurations>
<dependencies>
<!--dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="build-system->master"/-->
<dependency org="com.puppycrawl.tools" name="checkstyle" rev="5.9" conf="build-system->default"/>
<dependency org="com.google.code.findbugs" name="findbugs-ant" rev="3.0.0" conf="build-system->default"/>
<dependency org="net.sourceforge.pmd" name="pmd-java" rev="5.5.3" conf="build-system->default"/>
</dependencies>