【问题标题】:Apache Ivy resolve dependencies using Eclipse workspace during Ant buildApache Ivy 在 Ant 构建期间使用 Eclipse 工作区解决依赖关系
【发布时间】:2013-03-11 17:37:53
【问题描述】:

我正在使用 Apache Ivy 和 Eclipse (IvyDE) 并尝试解决以下问题。 我有两个项目,IvyParent 和 IvyChild,其中子项依赖于父项。我为 Eclipse Ivy Classpath Container 选择了“解决工作区中的依赖项”的选项。

Eclipse 自动构建器运行良好 - 我下载并包含了所有 Ivy 依赖项。 我同时打开了父项目和子项目,我可以对父项目进行实时编辑并查看子项目的编译更改。

问题是当我尝试使用 Ant 将子项目构建到 jar 中时。我的问题是,如何在显式 Ant 构建期间利用 Workspace 解析器?

我研究了 Ivy 文件系统解析器,但我试图避免的是必须在 Ant 构建子项目之前显式地重新构建父项目。

我得到的错误如下:

[ivy:retrieve] :: problems summary ::
[ivy:retrieve] :::: WARNINGS
[ivy:retrieve]      module not found: org.example#ParentModule;latest.integration
[ivy:retrieve]  ==== local: tried
[ivy:retrieve]  ...
[ivy:retrieve]  ==== shared: tried
[ivy:retrieve]  ...
[ivy:retrieve]  ==== public: tried
[ivy:retrieve]  ...
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      ::          UNRESOLVED DEPENDENCIES         ::
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      :: org.example#ParentModule;latest.integration: not found
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::

BUILD FAILED
C:\Users\user\workspace\IvyExampleChild\build.xml:15: impossible to resolve dependencies:
    resolve failed - see output for details

这里是父项目ivy.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">

    <info organisation="org.example" module="ParentModule" status="integration" />
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.6"/>
    </dependencies>
</ivy-module>

这里是子项目ivy.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">

    <info organisation="org.example" module="ChildModule" status="integration" />
    <dependencies>
        <dependency org="org.example" name="ParentModule" rev="latest.integration"/>
    </dependencies>
</ivy-module>

这是子 build.xml:

<project xmlns:ivy="antlib:org.apache.ivy.ant" name="ChildModule" default="release">    
    <property name="build.dir" value="build" />
    <property name="build.dir.classes" value="${build.dir}/classes" />

    <property name="src.dir" value="src" />
    <property name="output.jar" value="${build.dir}/${ant.project.name}.jar" />

    <target name="clean">
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${build.dir}" />
        </delete>
    </target>

    <target name="apache-ivy" depends="clean">
        <ivy:retrieve />
        <ivy:cachepath pathid="ivy.build.path" conf="default" />
    </target>

    <target name="release" depends="apache-ivy">
        <echo message="compiling ${src.dir}..." />

        <mkdir dir="${build.dir}" />
        <mkdir dir="${build.dir.classes}" />

        <javac srcdir="${src.dir}" destdir="${build.dir.classes}" classpathref="ivy.build.path"/>
        <jar destfile="${output.jar}" basedir="${build.dir}"/>
    </target>
</project>

【问题讨论】:

    标签: eclipse ant build ivy workspace


    【解决方案1】:

    这是一个解析器和发布问题。您的 ParentModule 构建需要将其 jar“发布”到特定目录。那么你的子模块构建应该使用可以找到这个特定目录的解析器。

    所以.. 例如,ivy_settings 可能看起来像:

    <ivysettings>
      <properties file="./ivysettings.properties"/>
      <property name="repository.dir" value="${ivy.build.dir}/repository"/>
      <settings defaultResolver="chain"/>
      <resolvers>
        <chain name="chain">
          <filesystem name="internal">
            <ivy pattern="${repository.dir}/[module]/ivy.xml" />
            <artifact pattern="${repository.dir}/[module]/[artifact].[ext]" />
          </filesystem>
          <ibiblio name="maven2" m2compatible="true"/>
        </chain>
      </resolvers>
    </ivysettings>
    

    你的 build.xml 文件应该有

      <ivy:settings file="${ivy.build.dir}/ivysettings.xml" />
    

    这里发生的事情是我们告诉 ivy 本地构建 jar 文件的目录 (...../repository)。

    所以你的父构建现在在它的 build.xml 中有一个“发布”目标:

    <target name="publish" depends="jar, jarSources" description="--> publish this project in the ivy repository">
      <delete file="${dist.dir}/lib/ivy.xml"/>
      <ivy:publish artifactspattern="${dist.dir}/lib/[artifact](-[classifier]).[ext]"
              resolver="internal"
              status="integration"
              overwrite="true"/>
      <echo message="project ${ant.project.name} integration published" />
    </target>
    

    所以.. 运行它并确认您的 ParentModule.jar 文件显示在您的存储库目录中。

    在那里,您的子模块应该能够“解析”您的父模块 jar 文件。

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 2016-10-11
      • 1970-01-01
      • 2013-06-30
      • 2015-02-16
      • 2016-01-06
      • 2011-01-24
      • 2010-12-14
      • 2011-01-24
      相关资源
      最近更新 更多