简体   繁体   English

ivy:检索选择要使用的ivy.xml文件

[英]ivy:retrieve select which ivy.xml file to use

Is there a way to select which ivy.xml file to use when I invoke ivy:retrieve ? 当我调用ivy:retrieve时,是否可以选择要使用的ivy.xml文件?

Looking at the documentation it appears that I can use the settingsRef property to select which IVY settings file to use but it's not the ivysettings.xml file I wish to modify, rather it's ivy.xml . 查看文档 ,看来我可以使用settingsRef属性来选择要使用的IVY设置文件,但这不是我想要修改的ivysettings.xml文件,而是ivy.xml My use case is the following: 我的用例如下:

  • I have a main ivy.xml file that I use to fetch my compile-time and run-time dependencies 我有一个主要的ivy.xml文件,用于获取编译时和运行时依赖项
  • I also have a number of build tool-chain dependencies, ie jars used by certain Ant tasks themselves (eg stuff like findbugs, cobertura, pmd, code style compliance checking etc.). 我也有许多构建工具链的依赖项,即某些Ant任务本身使用的jar(例如,诸如findbugs,cobertura,pmd,代码样式符合性检查之类的东西)。 That's stuff that's neither a compile time nor a run-time dependency of my code. 这些东西既不是我的代码的编译时也不是运行时的依赖项。 Moreover, it's the same in all the projects I am building with this tool chain so I'd like to be able to identify these dependencies in a single, separate ivy.xml file that I can simply copy across my projects. 此外,在我使用此工具链构建的所有项目中都是相同的,因此我希望能够在一个单独的ivy.xml文件中识别这些依赖关系,我可以在整个项目中复制这些文件。

Short anwer is to use ivy configurations: 简短的答案是使用常春藤配置:

http://ant.apache.org/ivy/history/latest-milestone/tutorial/conf.html http://ant.apache.org/ivy/history/latest-milestone/tutorial/conf.html

Ivy configurations can be used to group dependencies for different purposes. 常春藤配置可用于为不同目的对依赖项进行分组。 You don't need multiple ivy files. 您不需要多个常春藤文件。

Example

Here's my resolve target: 这是我的决心目标:

<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>

Which can then be used directly in my various tasks that require a classpath 然后可以将其直接用于需要类路径的各种任务中

<!-- 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"/>

..

Personally I only use the retrieve task to build archives. 我个人只使用检索任务来构建档案。 Here again I use configurations in order to control which jars I want: 在这里我再次使用配置来控制我想要的罐子:

<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>

IVY file IVY文件

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

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
        <conf name="build"   description="ANT task dependencies"/>
    </configurations>

    <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="compile->default"/>

        <!-- runtime dependencies -->
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.5" conf="runtime->default"/>

        <!-- test dependencies -->
        <dependency org="junit" name="junit" rev="4.11" conf="test->default"/>

        <!-- Build dependencies --> 
        <dependency org="org.codehaus.sonar-plugins" name="sonar-ant-task" rev="2.1" conf="build->default"/>
       <dependency org="org.jacoco" name="org.jacoco.ant" rev="0.6.3.201306030806" conf="build->default"/>

    </dependencies>

</ivy-module>

The desired configurations are declared at the top. 所需的配置在顶部声明。 Note how some are set operations. 注意如何进行一些设置操作。 For example The "compile" dependencies are automatically part of "runtime" and "test". 例如,“编译”依赖项自动成为“运行时”和“测试”的一部分。

Secondly the configuration mappings are critical: 其次,配置映射至关重要:

  • myconf->default : Includes transitive dependencies myconf-> default :包括传递依赖项
  • myconf->master : Just the module jar without dependencies myconf-> master :只是模块jar没有依赖项

Yes, but you have to specify the file in ivy:resolve , parameter is called file . 是的,但是您必须在ivy:resolve中指定文件,参数称为file The reason for his is that retrieve is a post resolve task . 他的原因是检索是一项后解决任务

So this is how I did it in the end: 所以这就是我最终的做法:

<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>

… where the file ivy-buildsystem.xml identifies only the dependencies of my Ivy tasks. …文件ivy-buildsystem.xml仅标识我的Ivy任务的依赖项。 Eg contains stuff like: 例如,包含以下内容:

<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>

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

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