本文介绍了Apache Ivy:解决安装程序中嵌入的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建时遇到问题,我必须通过 Apache Ivy 解决非标准工件.

I have a problem with a build where I have to resolve non-standard artifacts through Apache Ivy.

问题:

  • 我依赖于两个工件(a.jar 和 a-lib.jar).
  • 这两个依赖项仅作为单个安装程序 (a_installer.jar) 的一部分出现.
  • 可以下载安装程序,但不能下载嵌入的工件本身.
  • 可以操作安装程序来解压所需的依赖项.

要求:

  • 我必须在构建期间解析/下载工件(我无法将安装程序或提取的工件与我的代码一起保存).
  • 我无法使用存储库来存储提取的工件.
  • 子类化/扩展常春藤/任何都很好.

有没有人解决过类似的问题,或者分享一些有用的信息?

Has anyone solved a similar problem, or some helpful information to share?

或者,也许我以错误的方式解决问题?从我目前在网上发现的情况来看,人们似乎只是使用 Ivy 来下载文件并在事后手动(使用 Ant/其他)对它们进行后期处理,而不是真正解决更复杂的依赖项在常春藤中.

Or maybe I'm approaching the problem in the wrong way? From what I found so far on the web, people seem to use Ivy just to download files and post-process them manually (with Ant/whatever) after the fact, and not actually resolving more complicated dependencies within Ivy.

谢谢

PS:我不在乎安装程序是否也放入了ivy下载缓存,但我只想下载安装程序一次(而不是两个依赖项).>

推荐答案

调用ivy:retrieve"的问题是你还需要在你的ivy.xml中添加一个artifact"标签em>(完整的 URL)以检索在 Maven 存储库中找不到的依赖项...

The problem with a call to "ivy:retrieve" is that you need to also add an "artifact" tag in your ivy.xml (complete with URL) in order to retrieve a dependency not found in a Maven respository...

我不喜欢这个有两个原因

I don't like this for two reasons

  1. ivy.xml 应该只声明您的依赖项,而不是它们的位置.
  2. 需要在 build.xml 中添加额外的自定义逻辑来处理第 3 方包
  1. The ivy.xml should just declare your dependencies, not their locations.
  2. Need additonal custom logic in the build.xml to handle the 3rd party package

理想情况下,决定如何下载各种 jar 的应该是您的存储库设置,这就是我喜欢 packager 解析器的原因.即使我想要的库不在Maven中,我也可以配置ivy来处理.

Ideally it should be your repository settings that decide how to download the various jars, that is why I like the packager resolver. Even if the library I want is not in Maven, I can configure ivy to handle it.

以下是将 jreleaseinfo 项目转换为 ivy 依赖项的示例(托管在 sourceforge 中,我无法在 Maven 中找不到)

The following is an example of turning the jreleaseinfo project into an ivy dependency (hosted in sourceforge, I couldn't find it in Maven)

ivy.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="ivy_packager"/>
    <dependencies>
        <dependency org="ch.oscg" name="jreleaseinfo" rev="1.3.0"/>
    </dependencies>
</ivy-module>

声明两个解析器.默认为 Maven2,另一个是配置为在本地查找指令的 packager.(另见常春藤综述项目)

Declare two resolvers. Default is Maven2, the other is a packager configured to look locally for instructions. (See also the Ivy Roundup project)

ivysettings.xml

<ivysettings>
    <settings defaultResolver="maven2"/>
    <resolvers>
        <ibiblio name="maven2" m2compatible="true"/>

        <packager name="repackage" buildRoot="${user.home}/.ivy2/packager/build" resourceCache="${user.home}/.ivy2/packager/cache">
            <ivy pattern="file:///${basedir}/repository/[organisation]/[module]/[revision]/ivy.xml"/>
            <artifact pattern="file:///${basedir}/repository/[organisation]/[module]/[revision]/packager.xml"/>
        </packager>
    </resolvers>
    <modules>
        <module organisation="ch.oscg" name="jreleaseinfo" resolver="repackage"/>
    </modules>
</ivysettings>

魔法包含在打包程序"文件中.在解析时,这将用于生成一个 ANT 脚本,用于下载和提取所需的 jar.(无需将此逻辑放入您的 build.xml)

The magic is containing in the "packager" file. At resolve time this will be used to generate an ANT script that both downloads and extracts the required jars.(No need to put this logic into your build.xml)

repository/ch.oscg/jreleaseinfo/1.3.0/packager.xml

<packager-module version="1.0">

    <property name="name" value="${ivy.packager.module}"/>
    <property name="version" value="${ivy.packager.revision}"/>
    <property name="zipname" value="${name}-${version}"/>

    <resource dest="archive" url="http://sourceforge.net/projects/jreleaseinfo/files/jreleaseinfo/jreleaseinfo%201.3.0/jreleaseinfo-1.3.0.zip/download" sha1="9386d92758e627d04c2480b820731fd538b13a3f" type="zip"/>

    <build>

        <move file="archive/${zipname}/${zipname}.jar" tofile="artifacts/jars/${name}.jar"/>

    </build>
</packager-module>

为了减少文件数量,我省略了模块的 ivy.xml.这似乎是可选的,除非您想声明它的许可证和其他应该出现在公共存储库中的属性.

To reduce the number of files I omitted the module's ivy.xml. This appears to be optional unless you want to declare it's licence and other attributes that should be present in a public repository.

这篇关于Apache Ivy:解决安装程序中嵌入的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:24