以下示例使用 groovy。
David W. 提供了一个更简单的解决方案,它依赖于 ivy 2.3 中引入的新“orgPath”模式令牌。
例子
产生以下输出
├── 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
构建.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>
常春藤.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>