-1

我有一个实用程序项目,我使用 Ivy 和 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、the-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 缓存内部,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 决定在解析过程中从描述符中删除所有私有 conf(有意义)+ 源 conf + 源工件。我终其一生都无法理解为什么。我可以看到 XML 文件在 Artifactory 中很好——就像我写的一样。那么,为什么 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 -->

使困惑!

4

1 回答 1

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

项目1

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

常春藤.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>

项目2

构建.xml

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

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

</project>

常春藤.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>
于 2012-06-12T00:24:24.400 回答