首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >检索选择使用哪个ivy.xml文件

检索选择使用哪个ivy.xml文件
EN

Stack Overflow用户
提问于 2017-02-10 18:53:15
回答 3查看 2.2K关注 0票数 3

在我调用ivy.xml时,有选择使用哪个ivy:retrieve文件的方法吗?

在文件上的角度看,我似乎可以使用settingsRef属性来选择要使用哪个常春藤设置文件,但它不是我希望修改的ivysettings.xml文件,而是ivy.xml。我的用例如下:

  • 我有一个主ivy.xml文件,用于获取编译时和运行时依赖项。
  • 我还拥有许多构建工具链依赖项,即某些Ant任务本身使用的jars (例如findbug、cobertura、pmd、代码风格遵从性检查等)。这既不是编译时,也不是代码的运行时依赖。而且,在我用这个工具链构建的所有项目中都是一样的,因此我希望能够在一个单独的ivy.xml文件中识别这些依赖项,这样我就可以简单地跨项目复制这些依赖项。
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-02-14 18:34:34

最后我就是这样做的:

代码语言:javascript
运行
复制
<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-buildsystem.xml只标识我的常春藤任务的依赖项。例如,包含以下内容:

代码语言:javascript
运行
复制
<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>
票数 1
EN

Stack Overflow用户

发布于 2017-02-11 10:15:49

是的,但是必须在艾薇:决心中指定文件,参数称为file。他的原因是检索是一个后解决任务

票数 2
EN

Stack Overflow用户

发布于 2017-02-11 12:12:31

使用常春藤配置:

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

常春藤配置可用于为不同目的对依赖项进行分组。你不需要多个常春藤档案。

示例

我的目标是:

代码语言:javascript
运行
复制
<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>

,然后可以直接用于需要类路径的各种任务。

代码语言:javascript
运行
复制
<!-- 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"/>

..

就我个人而言,我只使用检索任务来构建档案。在这里,我再次使用配置来控制我想要的jars:

代码语言:javascript
运行
复制
<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>

常春藤档案

代码语言:javascript
运行
复制
<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->default:包括传递依赖项
  • myconf->master:只是没有依赖项的模块jar
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42166680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档