artifactreport任务可用于生成 XML 文件,详细说明配置中的工件:
<ivy:artifactreport tofile="build/runtime.xml" conf="runtime"/>
这是一个稍微不同的解决方案,它结合了groovy和 ivy cachefileset任务,根据编译依赖项生成 Eclipse“.classpath”文件
<macrodef name="eclipse">
<attribute name="srcdir"/>
<attribute name="outputdir"/>
<attribute name="classpathref" default="build.path"/>
<attribute name="conf" default="compile"/>
<sequential>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="@{classpathref}"/>
<ivy:cachefileset setid="libfiles" conf="@{conf}"/>
<groovy>
<arg value="@{srcdir}"/>
<arg value="@{outputdir}"/>
import groovy.xml.MarkupBuilder
//
// Generate the classpath file
//
// The "lib" classpathentry fields are populated using the ivy artifact report
//
project.log("Creating .classpath")
new File(".classpath").withWriter { writer ->
def xml = new MarkupBuilder(writer)
xml.classpath() {
classpathentry(kind:"src", path:args[0])
classpathentry(kind:"output", path:args[1])
classpathentry(kind:"con", path:"org.eclipse.jdt.launching.JRE_CONTAINER")
project.references.libfiles.each {
classpathentry(kind:"lib", path:it)
}
}
}
</groovy>
</sequential>
</macrodef>