使用ivy:retrieve将组织名称拆分为嵌套文件夹

时间:2013-02-28 08:41:52

标签: ant ivy

在常春藤中,我可以设置检索模式,以便在我想要的地方复制所有依赖项。

例如:

 <ivy:retrieve pattern="${local-maven2-dir}/[organisation]/[module]/[revision]/[module]-[revision].[ext]" conf="compile" type="jar,bundle" sync="true"/>

我想知道是否可以将组织视为一个文件夹,而不是作为一组嵌套文件夹,并保留在最深的文件夹(这是修订版)jar包,就像jar存储在maven默认仓库中一样。

所以,基本上我想让jar放在像

这样的路径中
com/yahoo/platform/yui/yuicompressor/2.4.7

而不喜欢

com.yahoo.platform.yui/yuicompressor/2.4.7

PS:涉及groovy脚本计算也是一个有效的解决方案,只是我不知道如何在这里涉及groovy。

2 个答案:

答案 0 :(得分:3)

实际上,它很容易并且已在Ivy中记录(看在页面底部附近)。您可以使用[orgPath]

<ivy:retrieve conf="compile"
    type="jar,bundle"
    sync="true"
    pattern="${local-maven2-dir}/[orgPath]/[module]-[revision].[ext]"/>

答案 1 :(得分:1)

以下示例使用groovy。

David W.提供了一个更简单的解决方案,依赖于新的&#34; orgPath&#34;常春藤2.3中引入的模式标记。

实施例

生成以下输出

├── build
│   ├── com
│   │   └── yahoo
│   │       └── platform
│   │           └── yui
│   │               └── yuicompressor
│   │                   └── 2.4.7
│   │                       └── yuicompressor-2.4.7.jar
│   └── rhino
│       └── js
│           └── 1.6R7
│               └── js-1.6R7.jar
├── build.xml
└── ivy.xml

的build.xml

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

    <target name="resolve">
        <ivy:resolve/>
        <ivy:cachepath pathid="build.path" conf="build"/>
    </target>

    <target name="retrieve" depends="resolve">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

        <ivy:artifactproperty conf="compile" name="index.[module].[artifact]" value="[module].[artifact]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].organisation" value="[organisation]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].module" value="[module]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].artifact" value="[artifact]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].revision" value="[revision]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].ext" value="[ext]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].cachefile" value="${ivy.cache.dir}/[organisation]/[module]/jars/[artifact]-[revision].[ext]"/>

        <groovy>
            modules = properties.findAll { it.toString().startsWith("index.") }

            modules.each { key, value ->
                def organisation = properties[value+".organisation"].replace(".","/")
                def module = properties[value+".module"]
                def artifact = properties[value+".artifact"]
                def revision = properties[value+".revision"]
                def ext = properties[value+".ext"]
                def cachefile = properties[value+".cachefile"]

                ant.copy(file:cachefile, tofile:"build/${organisation}/${module}/${revision}/${artifact}-${revision}.${ext}")
            }
        </groovy>
    </target>
</project>

的ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="build"   description="Build dependencies"/>
        <conf name="compile" description="Compile classpath"/>
    </configurations>

    <dependencies>
        <!-- build dependencies -->
        <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.1.1" conf="build->default"/>

        <!-- compile dependencies -->
        <dependency org="com.yahoo.platform.yui" name="yuicompressor" rev="2.4.7" conf="compile->default"/>
    </dependencies>

</ivy-module>