让 ivy:retrieve 不将 jar 复制到两个配置中?

发布于 2024-09-06 22:58:51 字数 1046 浏览 7 评论 0原文

我正在尝试设置我的 ant 构建,以便运行 Ivy 函数的目标与持续构建和大多数开发人员运行的目标完全分开。我希望一个目标下载更新的依赖项,我将签入该依赖项。其他目标将通过包含相关目录中的 *.jar 来设置其类路径。

我有两个配置:

<configurations>
    <conf name="compile" />
    <conf name="test" />
</configurations>

我有一些依赖项:

<dependency
    org="my.org"
    name="some-lib"
    rev="latest.release"
    conf="compile->default" />
<dependency
    org="my.org"
    name="some-test-lib"
    rev="latest.release"
    conf="test->default" />

我使用 ivy:retrieve 下载这些依赖项及其传递依赖项:

<ivy:retrieve
    pattern="lib/[conf]/[type]/[artifact]-[revision].[ext]"
    sync="true"
    file="ivy.xml" />

问题是我在编译目录和测试目录之间看到一些重复的 jar 文件,这些文件来自传递依赖项。由于我想签入所有这些 jar 并使用它们来创建类路径,因此我想避免重复。这可能吗?

lib/compile/jar/some-lib-1.0.jar
lib/compile/jar/slf4j-api-1.5.11.jar
lib/test/jar/some-test-lib-1.0.jar
lib/test/jar/junit-4.7.jar
lib/test/jar/slf4j-api-1.5.11.jar

I'm trying to set up my ant build so that the targets which run Ivy functions are completely separated from the ones that the continuous build and most developers run. I want one target to download updated dependencies, which I'll check in. Other targets will set up their classpath by including *.jar from the relevant directory.

I have two configurations:

<configurations>
    <conf name="compile" />
    <conf name="test" />
</configurations>

I have some dependencies:

<dependency
    org="my.org"
    name="some-lib"
    rev="latest.release"
    conf="compile->default" />
<dependency
    org="my.org"
    name="some-test-lib"
    rev="latest.release"
    conf="test->default" />

And I download those dependencies and their transitive dependencies using ivy:retrieve:

<ivy:retrieve
    pattern="lib/[conf]/[type]/[artifact]-[revision].[ext]"
    sync="true"
    file="ivy.xml" />

The problem is that I'm seeing some duplicates jars between the compile and the test directories, which come from transitive dependencies. Since I want to check in all these jars and use them for creating classpaths, I'd like to avoid duplicates. Is this possible?

lib/compile/jar/some-lib-1.0.jar
lib/compile/jar/slf4j-api-1.5.11.jar
lib/test/jar/some-test-lib-1.0.jar
lib/test/jar/junit-4.7.jar
lib/test/jar/slf4j-api-1.5.11.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北渚 2024-09-13 22:58:51

这不是重复,每个配置都是一组单独的 jar,并且 ivy restrieve 任务忠实地创建每个组......

也许直接创建类路径而不是填充一个类路径更有意义本地 lib 目录。

这是我的 ANT 构建文件的片段:

<target name="get-dependencies">
    <ivy:resolve/>

    <ivy:cachepath pathid="compile.path" conf="compile" />
    <ivy:cachepath pathid="test.path" conf="test" />
</target>

<target name="compile" depends="get-dependencies">
    <javac srcdir="src" destdir="build/classes" classpathref="compile.path"/>
</target>

当我需要创建一组 jar 的本地副本(例如组装 Web 应用程序的目录)时,我通常只使用 ivy retrieve 任务:

<ivy:retrieve pattern="build/WEB_INF/lib/[artifact].[ext]" conf="runtime"/>

更新

另一种选择是指示ivy在下载瞬态依赖项时排除slf4j模块,如下:

<dependency org="my.org" name="some-lib" rev="latest.release" conf="compile->default">
    <exclude module="slf4j-api"/> 
</dependency>

<dependency org="my.org" name="some-test-lib" rev="latest.release" conf="test->default">
    <exclude module="slf4j-api"/> 
</dependency>

This is not duplication, each configuration is a separate set of jars and the ivy restrieve task is faithly creating each set....

Perhaps it would make more sense to create the classpaths directly, rather than populating a local lib directory.

Here's a snippet of my ANT build files:

<target name="get-dependencies">
    <ivy:resolve/>

    <ivy:cachepath pathid="compile.path" conf="compile" />
    <ivy:cachepath pathid="test.path" conf="test" />
</target>

<target name="compile" depends="get-dependencies">
    <javac srcdir="src" destdir="build/classes" classpathref="compile.path"/>
</target>

I normally only use the ivy retrieve task when I need to create a local copy of a set of jars, for example assembling a web app's directory:

<ivy:retrieve pattern="build/WEB_INF/lib/[artifact].[ext]" conf="runtime"/>

Update

Another alternative is to instruct ivy to exclude the slf4j module when downloading transient dependencies, as follows:

<dependency org="my.org" name="some-lib" rev="latest.release" conf="compile->default">
    <exclude module="slf4j-api"/> 
</dependency>

<dependency org="my.org" name="some-test-lib" rev="latest.release" conf="test->default">
    <exclude module="slf4j-api"/> 
</dependency>
爱本泡沫多脆弱 2024-09-13 22:58:51

如果我能直接通过 Ivy 来做到这一点,那就最好了。现在我已经通过使用ant删除重复项解决了这个问题。

If I can do this through Ivy directly, that would be best. For now I've solved the problem by just deleting duplicates using ant.

萌无敌 2024-09-13 22:58:51

尝试以下操作。你的测试应该扩展编译

<dependency
org="my.org"
name="some-test-lib"
rev="latest.release"
conf="**test->compile**" />

如果我是对的,IVY 应该发现测试扩展了编译并且只会下载 slf4j 一次。

Try the following. Your test should extend compile

<dependency
org="my.org"
name="some-test-lib"
rev="latest.release"
conf="**test->compile**" />

If i am right IVY should find that test extends compile and would download slf4j only once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文