Apache Ivy 在 Ant 构建期间使用 Eclipse 工作区解析依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15560601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache Ivy resolve dependencies using Eclipse workspace during Ant build
提问by earthbounce
I'm using Apache Ivy with Eclipse (IvyDE) and trying to solve the following issue. I have two projects, IvyParent and IvyChild, where the child depends on the parent.I have the option selected for Eclipse Ivy Classpath Container to "Resolve dependencies in workspace".
我在 Eclipse (IvyDE) 中使用 Apache Ivy 并尝试解决以下问题。我有两个项目,IvyParent 和 IvyChild,孩子依赖于父母。我为 Eclipse Ivy Classpath Container 选择了“解决工作区中的依赖关系”的选项。
The Eclipse autobuilder is working great - I get all my Ivy dependencies downloaded and included. I have both the parent and child projects open and I can make realtime edits to the parent and see the compilation changes in the child.
Eclipse 自动生成器运行良好 - 我下载并包含了所有 Ivy 依赖项。我同时打开了父项目和子项目,我可以对父项目进行实时编辑并查看子项目的编译更改。
The problem is when I try to use Ant to build the child project into a jar. My question is, how can I leverage the Workspace resolver during an explicit Ant build?
问题是当我尝试使用 Ant 将子项目构建到 jar 中时。我的问题是,如何在显式 Ant 构建期间利用 Workspace 解析器?
I've looked into Ivy filesystem resolvers, but what I'm trying to avoid is having to Ant rebuild the parent project explicitly before Ant building the child.
我已经研究过 Ivy 文件系统解析器,但我试图避免的是在 Ant 构建子项目之前必须显式地重建父项目。
The error I get is the following:
我得到的错误如下:
[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
Here is the parent project ivy.xml:
这是父项目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>
Here is the child project ivy.xml:
这是子项目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>
Here is the child build.xml:
这是子 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>
回答by ticktock
This is a resolver and publishing problem. Your build for your ParentModule needs to 'publish' its jar to a specific directory. Then your child module build should be using a resolver that can find this specific directory.
这是一个解析器和发布问题。您的 ParentModule 构建需要将其 jar“发布”到特定目录。那么你的子模块构建应该使用一个可以找到这个特定目录的解析器。
So.. for example, ivy_settings might look like:
所以.. 例如,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>
and your build.xml files should have
你的 build.xml 文件应该有
<ivy:settings file="${ivy.build.dir}/ivysettings.xml" />
What's happening here is we're telling ivy about a directory (...../repository) for the locally build jar files.
这里发生的事情是我们告诉 ivy 有关本地构建 jar 文件的目录 (...../repository)。
So your parent build now has in it's build.xml a 'publish' target:
所以你的父构建现在在它的 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>
So.. run that and confirm your ParentModule.jar file shows up in your repository directory.
所以.. 运行它并确认您的 ParentModule.jar 文件出现在您的存储库目录中。
Once there, your child module should be able to 'resolve' your parent module jar file.
到达那里后,您的子模块应该能够“解析”您的父模块 jar 文件。