2017-02-10 67 views
0

有没有办法选择当我调用ivy:retrieve时使用哪个ivy.xml文件?常春藤:检索选择使用哪个ivy.xml文件

寻找at the documentation看来我可以使用settingsRef属性来选择其中IVY设置文件使用,但它不是ivysettings.xml文件我想修改,而它的ivy.xml。我的使用情况如下:

  • 我有一个主ivy.xml文件,我用它来取我的编译时和运行时的依赖
  • 我也有一些构建工具链的依赖关系,即罐子由某些Ant任务自己使用(例如findbugs,cobertura,pmd,代码样式符合性检查等)。这是既不是编译时间也不是我的代码的运行时依赖。此外,在我使用此工具链构建的所有项目中都是如此,因此我希望能够在单个独立的ivy.xml文件中识别这些依赖关系,我可以简单地在我的项目中进行复制。

回答

0

所以模块罐子这就是我最后的表现:

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

&hellip;文件ivy-buildsystem.xml只标识了我常春藤任务的依赖关系。例如。包含以下内容:

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

短前面回答是使用常春藤配置:

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

常春藤配置可用于为不同的目的组依赖关系。你不需要多个常春藤文件。

这里是我的决心,目标:

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

.. 

个人各种任务直接使用我只用检索任务建立档案。在这里,我再次使用,为了控制我想这瓶配置:

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

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

所希望的配置在顶部声明。请注意如何设置一些操作。例如,“编译”依赖关系自动成为“运行时”和“测试”的一部分。

其次配置映射是关键:

  • myconf->默认:包括传递依赖
  • myconf->主:只要不依赖
+0

Upvoted。但是,我意识到采用不同配置的可能性。我特别要求提供单独的IVY文件,因为我喜欢在多个项目中具有相同的“ANT任务依赖项”,并且具有单独的IVY文件可以很容易地检查(使用差异甚至符号链接),而使用解决方案时,您必须直观地检查文件来确保“ANT任务依赖性”确实是相同的(当然,这对你来说很重要)。我相信我已经实现了,但直到我发布自己的答案,我很高兴接受你的答案,因为这是一个伟大的写作。 –

+0

顺便提一句,我不喜欢使用'ivy:cachepath',因为它对于实际包含的罐子有点不透明。即使对于“ANT任务依赖”,我也使用“ivy:retrieve”,因为我喜欢能够检查文件系统上的目录并查看所有带入的jar。“ivy:cachepath”没有提供这样的可见性我知道。 –

+0

@MarcusJuniusBrutus请注意,我的“解决方案”目标是如何使用常青藤“报告”任务来生成每个配置上罐子的详细报告。 –