常春藤:解决从描述符中删除confs

时间:2012-06-11 15:18:21

标签: ivy artifactory

我有一个公用事业项目,我使用Ivy& amp; Ant并发布到Artifactory:

用于utils项目的ivy.xml:

<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://ant.apache.org/ivy/maven"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
            version="2.0">
    <info organisation="org.abc" module="utils"/>

    <configurations defaultconfmapping="%->default,sources">
        <conf name="default"/>
        <conf name="sources"/>
        <conf name="compile-main" extends="default" visibility="private" transitive="false"/>
        <conf name="compile-test" extends="compile-main" visibility="private" transitive="false"/>
        <conf name="run-test" extends="compile-test" visibility="private" transitive="true"/>
    </configurations>

    <publications>
        <artifact name="utils" type="jar"/>
        <artifact name="utils-src" type="source" ext="zip" conf="sources" m:classifier="sources"/>
    </publications>

    <dependencies>
        <--snip... -->
    </dependencies>
</ivy-module>

这很好用。我可以看到JAR,-sources.zip和Ivy描述符发布到Artifactory就好了。

然后我尝试在依赖项目中使用此JAR:

依赖项目的ivy.xml:

<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://ant.apache.org/ivy/maven"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
            version="2.0">
    <info organisation="org.abc" module="dependent"/>

    <configurations defaultconfmapping="%->default,sources">
        <conf name="default"/>
        <conf name="compile-main" extends="default" visibility="private" transitive="false"/>
        <conf name="compile-test" extends="compile-main" visibility="private" transitive="false"/>
        <conf name="run-test" extends="compile-test" visibility="private" transitive="true"/>
    </configurations>

    <dependencies> 
        <dependency org="org.abc" name="utils" rev="latest.integration" conf="default"/> 
        <!-- snip... -->
    </dependencies>
</ivy-module>

如果我将依赖项目的defaultconfmapping更改为%->default,一切正常。当我将defaultconfmapping设置为%->default,sources时,其他依赖项(JUnit,log4j等)的源代码可以正常下载,但我的utils项目源代码出错:

[ivy:resolve] :: problems summary ::
[ivy:resolve] :::: WARNINGS
[ivy:resolve]       ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve]       ::          UNRESOLVED DEPENDENCIES         ::
[ivy:resolve]       ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve]       :: org.abc#utils;20120611153645: configuration not found in org.abc#utils;20120611153645: 'sources'. It was required from org.abc#dependent;working@blah.abc.org default
[ivy:resolve]       ::::::::::::::::::::::::::::::::::::::::::::::

有趣的是,如果我查看常春藤缓存,Ivy XML文件看起来像这样:

<ivy-module version="2.0">
    <info organisation="org.abc"
            module="utils"
            revision="20120611153645"
            status="release"
            publication="20120611154459"
            default="true"
    />
    <configurations>
            <conf name="default" visibility="public"/>
    </configurations>
    <publications>
            <artifact name="utils" type="jar" ext="jar" conf="default"/>
    </publications>
</ivy-module>

因此,出于某种原因,Ivy决定在解析过程中删除所有私有confs(有意义)+来源conf +来自描述符的sources工件。我不能为我的生活理解为什么。我可以看到Artifactory中的XML文件很好 - 就像我写的那样。那么,为什么Ivy在解决它时放弃了源信息呢?

供参考,这是我的Ant脚本的早期部分:

<ivy:configure url="http://repo:8081/artifactory/simple/bootstrap-local/ivysettings.xml"/>
<ivy:resolve log="downloadOnly"/>
<fail message="Go check out the cache file now"/> <!-- added to find out whether resolve or retrieve broke it -->

困惑!

1 个答案:

答案 0 :(得分:1)

无法重现您的问题。也许这个有用的例子会有所帮助......

测试

|-- proj1
|   |-- build.xml
|   `-- ivy.xml
`-- proj2
    |-- build.xml
    `-- ivy.xml

运行构建后如下

ant -f ./proj1/build.xml
ant -f ./proj2/build.xml

具有以下文件结构

|-- proj1
|   |-- build
|   |   |-- ivy.xml
|   |   |-- utils.jar
|   |   `-- utils-src.zip
|   |-- build.xml
|   `-- ivy.xml
`-- proj2
    |-- build.xml
    |-- ivy.xml
    `-- lib
        `-- utils-20120612011906.jar

proj1

的build.xml

<project name="demo" default="run" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="init">
        <echo file="build/utils.jar"/>
        <echo file="build/utils-src.zip"/>
    </target>

    <target name="run" depends="init">
        <ivy:resolve/>

        <ivy:publish resolver="local">
            <artifacts pattern="build/[artifact].[ext]" />
        </ivy:publish>    
    </target>

</project>

的ivy.xml

<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://ant.apache.org/ivy/maven"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
            version="2.0">
    <info organisation="org.abc" module="utils"/>

    <configurations>
        <conf name="default"/>
        <conf name="sources"/>
    </configurations>

    <publications>
        <artifact name="utils" type="jar" conf="default"/>
        <artifact name="utils-src" type="source" ext="zip" conf="sources" m:classifier="sources"/>
    </publications>

</ivy-module>

proj2

的build.xml

<project name="demo" default="run" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="run">
        <ivy:retrieve/>
    </target>

</project>

的ivy.xml

<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://ant.apache.org/ivy/maven"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
            version="2.0">
    <info organisation="org.abc" module="utils-use"/>

    <configurations>
        <conf name="default"/>
        <conf name="sources"/>
    </configurations>

    <dependencies>
        <dependency org="org.abc" name="utils" rev="latest.integration" conf="default"/> 
    </dependencies>

</ivy-module>