文件系统解析器和传递依赖项/主配置 [英] filesystem resolver and transitive dependencies / master configurations

查看:60
本文介绍了文件系统解析器和传递依赖项/主配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用filesystem解析器设置了Ivy,如在此答案中所述所述. IE.将我的jar放在"lib"目录中,并配置一个filesystem解析器以从那里拾取它们(而不是使用默认的ibiblio解析器).

I have setup Ivy with a filesystem resolver as explained in this answer. I.e. placing my jars in a 'lib' directory and configuring a filesystem resolver to pick them up from there (instead of using the default ibiblio resolver).

文件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也非常简单,出于测试目的,我只定义了一个配置:

My ivy.xml is also very simple and for test purposes I only define a single configuration:

<?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元素以获取"master"而不是"default"配置:

The above works and the dependency is properly retrieved from the lib directory. However I've noticed that if I change the dependency element in the ivy.xml file to fetch the "master" as opposed to the "default" configuration:

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

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

… then it no longer works and I get the following:

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

因此,即使找到了模块,也没有找到其主"配置.

So even though the module is found it's "master" configuration is not found.

要完成此工作,我需要将theConf->master更改为theConf->default,或者干脆完全删除conf映射.

To make this work I either need to change theConf->master to theConf->default or simply remove the conf mapping altogether.

对此进行了进一步的思考,我意识到我还不理解使用filesystem解析器来拾取放置在目录内部的jar的解析器应该如何区分不同的配置和获取,例如仅编译时间与模块的传递依赖关系.

Further reflecting upon this I realized that I also don't understand how a filesystem resolver that's picking up jars laid out flat insider a directory is supposed to distinguish between different configurations and fetch, e.g. only compile time versus transitive dependencies of a module.

无论如何,必须始终使用默认"配置会给我带来麻烦,因为我必须修改我的ivy.xml文件.当我使用ibiblio解析器进行解析时,通常在ivy.xml中有一个:

At any rate having to always use the "default" configuration causes me problems as I have to modify my ivy.xml file. When I resolve using the ibiblio resolver I typically have in my ivy.xml either:

conf="compile->master"

…或:

conf="runtime->default"

…取决于我是否需要传递依赖.无论我已配置为在ivysettings.xml中使用的解析器,我都希望保留相同的ivy.xml文件.

… depending on whether I want the transitive dependencies or not. I would like to keep the same ivy.xml file regardless of the resolver I have configured to use in ivysettings.xml.

我的问题是:

  1. 是否可以为ibibliofilesystem解析器保留相同的ivy.xml文件,并且在这种情况下如何处理主"配置?
  2. filesystem解析器如何理解配置,这些解析器拾取放置在目录内的jar容器?
  3. 是否可以配置filesystem解析器,以便也可以通过依赖项获取传递依赖关系,并且在这种情况下文件系统结构应该是什么?
  4. 我只是将jar复制到filesystem解析程序正在查看的目录中.我是否应该改用某种导入机制(例如,创建适当的目录结构,该结构可能允许解析程序也获取传递性依赖项).
  1. is it possible to keep the same ivy.xml file for both the ibiblio and the filesystem resolver and what to do with "master" configurations in such a case?
  2. how are configurations understood by a filesystem resolver that's picking up jars that are laid flat inside a directory?
  3. is it possible to configure a filesystem resolver such that transitive dependencies can also be fetched with a dependency and what should be the file system structure in such a case?
  4. I am simply copying jars inside the directory that the filesystem resolver is looking at. Should I be using some importation mechanism instead (e.g. to create the proper directory structure that might perhaps allow the resolver to also fetch transitive dependencies).

推荐答案

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

I gave up using a flat directory structure with just a bunch of jars. It is clear to me now that in addition to the jars, declarative files need to be present to properly identify the dependencies of each module.

我发现的工作原理是使用ivy:install任务将我需要的依赖项从ibiblio解析器导入到我的本地filesystem解析器中.大致按

What I have discovered works is to use the ivy:install task to import the dependencies I need from the ibiblio resolver into my local filesystem resolver. More or less as described in this post.

我创建了一个build-import-Maven-dependencies-to-local.xml脚本来自动执行此过程.加上一些聪明"(不是很关键,您可以省去),以便逐行对齐所有依赖项,如下所示(要点是最后一个目标,安装"):

I've created a build-import-Maven-dependencies-to-local.xml script to automate this process. With some added "cleverness" (which is not crucial and you can dispense with) for aligning all the dependencies visually line after line it looks like the following (the gist is the last target, "install"):

<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.

Resolvers "public" and "local" are defined in the ivysettings.file and correspond to ibiblio and filesystem respectively.

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

This creates the correct structure and places ivy-x.y.z.xml files that provide the necessary information. This is a partial example of the directory structure that got created in my system and the files that are present.

$ 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)依赖项一样发挥作用.

Once this is in place the filesystem resolver works like a charm for both transitive (default) and compile-time (master) dependencies.

这篇关于文件系统解析器和传递依赖项/主配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆