【问题标题】:filesystem resolver and transitive dependencies / master configurations文件系统解析器和传递依赖/主配置
【发布时间】:2017-06-25 02:43:59
【问题描述】:

按照in this answer 的说明,我已经使用filesystem 解析器设置了Ivy。 IE。将我的 jar 放在“lib”目录中并配置 filesystem 解析器以从那里获取它们(而不是使用默认的 ibiblio 解析器)。

文件ivysettings.xml如下:

<ivysettings>
  <caches defaultCacheDir="${ivy.settings.dir}/cache"/>
  <settings defaultResolver="local"/>
  <resolvers>
     <filesystem name="local">
        <artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/>
     </filesystem>
  </resolvers>
</ivysettings>

我的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="foo" module="foo" status="foo"/>
    <configurations>
        <conf name="theConf"  description="just one configuration"/>
    </configurations>
    <dependencies>
        <dependency org="org.apache.commons" name="commons-lang3" rev="3.1" conf="theConf->default"/>
    </dependencies>
</ivy-module>

上述方法有效,并且从lib 目录中正确检索了依赖项。但是我注意到,如果我更改 ivy.xml 文件中的依赖元素以获取“主”而不是“默认”配置:

<dependency org="org.apache.commons" name="commons-lang3" rev="3.1" conf="theConf->master"/>

…然后它不再起作用,我得到以下信息:

resolve: [ivy:resolve] :: Apache Ivy 2.4.0-local-20161112135640 -
20161112135640 :: http://ant.apache.org/ivy/ :: [ivy:resolve] ::
loading settings :: file =
/home/mperdikeas/play/ivy-with-local-filesystem/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: foo#foo;working@mp-t420
[ivy:resolve]   confs: [theConf] [ivy:resolve]  found
org.apache.commons#commons-lang3;3.1 in local [ivy:resolve] ::
resolution report :: resolve 66ms :: artifacts dl 0ms
---------------------------------------------------------------------
|                  |            modules            ||   artifacts   |
|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
|      theConf     |   1   |   0   |   0   |   0   ||   0   |   0   |
---------------------------------------------------------------------
[ivy:resolve]  [ivy:resolve] :: problems summary :: [ivy:resolve] ::::
WARNINGS [ivy:resolve]
    :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve]        ::   
UNRESOLVED DEPENDENCIES         :: [ivy:resolve]
    :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve]        ::
org.apache.commons#commons-lang3;3.1: configuration not found in
org.apache.commons#commons-lang3;3.1: 'master'. It was required from
foo#foo;working@mp-t420 theConf [ivy:resolve]
    :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve] 
[ivy:resolve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS

因此,即使找到该模块,也找不到它的“主”配置。

要完成这项工作,我需要将 theConf-&gt;master 更改为 theConf-&gt;default 或干脆完全删除 conf 映射。

进一步反思这一点,我意识到我也不明白 filesystem 解析器是如何拾取 jar 的,该解析器在一个目录中放置扁平的内部目录应该区分不同的配置和获取,例如仅编译时间与模块的传递依赖关系。

无论如何,必须始终使用“默认”配置会给我带来问题,因为我必须修改我的 ivy.xml 文件。当我使用 ibiblio 解析器解析时,我的 ivy.xml 中通常有:

conf="compile->master"

… 或:

conf="runtime->default"

... 取决于我是否想要传递依赖。我想保留相同的ivy.xml 文件,无论我配置为在ivysettings.xml 中使用什么解析器。

我的问题是:

  1. 是否可以为ibibliofilesystem 解析器保留相同的ivy.xml 文件,以及在这种情况下如何处理“主”配置?
  2. filesystem 解析器如何理解配置,该解析器正在拾取平放在目录中的 jars?
  3. 是否可以配置一个filesystem 解析器,以便也可以通过依赖项获取传递依赖项,在这种情况下文件系统结构应该是什么?
  4. 我只是在filesystem 解析器正在查看的目录中复制jar。我是否应该改用某种导入机制(例如,创建正确的目录结构,这可能允许解析器也获取传递依赖项)。

【问题讨论】:

  • 您似乎已经回答了自己的问题。基本上你可以选择在你的“lib”目录中包含常春藤文件来定义每个模块的配置和依赖关系。

标签: java ivy


【解决方案1】:

我放弃了使用只有一堆 jar 的平面目录结构。现在我很清楚,除了 jars 之外,还需要提供声明性文件以正确识别每个模块的依赖关系。

我发现的工作是使用ivy:install 任务将我需要的依赖项从ibiblio 解析器导入我的本地filesystem 解析器。或多或少如in this post 所述。

我创建了一个build-import-Maven-dependencies-to-local.xml 脚本来自动化这个过程。加上一些额外的“聪明”(这不是至关重要的,您可以省去),以便在视觉上一行一行地对齐所有依赖项,如下所示(要点是最后一个目标,“安装”):

<project name="local repository importation" default="install-deps-locally"
         xmlns:contrib="http://net.sf.antcontrib"
         xmlns:ivy="antlib:org.apache.ivy.ant">

    <taskdef uri="http://net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/tools/ant-contrib.jar" />

    <target name="install-deps-locally" description="local at non default location">
        <!-- "iw" starts for "Import Wrapper" and "d" stands for "dependency" -->
        <antcall target="iw"><param name="d" value="javax.servlet              javax.servlet-api   3.1.0"   /></antcall>
        <antcall target="iw"><param name="d" value="com.google.code.gson       gson                2.8.0"   /></antcall>
        <antcall target="iw"><param name="d" value="junit                      junit               4.12"    /></antcall>
    </target>

    <target name="iw"> <!-- "iw" stands for "Import Wrapper" and "d" stands for "dependency" -->
        <property name="REGULAR_EXPRESSION" value="(\S*)(\s*)(\S*)(\s*)(\S*)"/>
        <contrib:propertyregex property="organisation"
                       input="${d}"
                       regexp="${REGULAR_EXPRESSION}"
                       select="\1"
                       casesensitive="false"/>
        <contrib:propertyregex property="module"
                       input="${d}"
                       regexp="${REGULAR_EXPRESSION}"
                       select="\3"
                       casesensitive="false"/>
        <contrib:propertyregex property="revision"
                       input="${d}"
                       regexp="${REGULAR_EXPRESSION}"
                       select="\5"
                       casesensitive="false"/>
        <antcall target="install">
            <param name="organisation" value="${organisation}"/>
            <param name="module"       value="${module}"/>
            <param name="revision"     value="${revision}"/>
        </antcall>
    </target>

    <target name="install" description="import module from public Maven repository into local repository">
        <ivy:settings id="ivysettings-ibiblio-to-local" file="ivysettings-ibiblio-to-local.xml"/>
        <ivy:install settingsRef="ivysettings-ibiblio-to-local"
                     organisation="${organisation}"
                     module="${module}"
                     revision="${revision}"
                     from="public"
                     to="local"
                     transitive="true"
                     overwrite="true"/>
    </target>    
</project>

解析器“public”和“local”在ivysettings.file中定义,分别对应ibibliofilesystem

这将创建正确的结构并放置提供必要信息的ivy-x.y.z.xml 文件。这是在我的系统中创建的目录结构和存在的文件的部分示例。

$ tree repo/ | head -20
repo/
├── avalon-framework
│   └── avalon-framework
│       ├── ivys
│       │   ├── ivy-4.1.5.xml
│       │   ├── ivy-4.1.5.xml.md5
│       │   └── ivy-4.1.5.xml.sha1
│       └── jars
│           ├── avalon-framework-4.1.5.jar
│           ├── avalon-framework-4.1.5.jar.md5
│           └── avalon-framework-4.1.5.jar.sha1
├── com.google.code.findbugs
│   └── jsr305
│       ├── ivys
│       │   ├── ivy-1.3.9.xml
│       │   ├── ivy-1.3.9.xml.md5
│       │   └── ivy-1.3.9.xml.sha1
│       └── jars
│           ├── jsr305-1.3.9.jar
│           ├── jsr305-1.3.9.jar.md5

一旦到位,filesystem 解析器就像是传递 (default) 和编译时 (master) 依赖项的魅力。

【讨论】:

    猜你喜欢
    • 2019-10-04
    • 2016-11-11
    • 2014-10-15
    • 1970-01-01
    • 2016-06-14
    • 2021-11-02
    • 1970-01-01
    • 2021-08-18
    • 2023-03-16
    相关资源
    最近更新 更多