ant能否生成一个统一的脚本,包括与maven';类似的所有导入;什么是有效的聚甲醛?

ant能否生成一个统一的脚本,包括与maven';类似的所有导入;什么是有效的聚甲醛?,ant,Ant,我有一个ant脚本,它导入了其他脚本,这些脚本导入了其他脚本,这些脚本指向可以进行定义的地方网络 ant能否像maven的帮助:effective pom那样导入所有定义并输出一个文件 我想将此作为输出文件添加到我的构建中,以使调试更容易。您可以创建另一个目标,该目标将创建此类文件。例如,它可以如下所示: main build.xml,它可以完成一些工作,还可以生成有效的构建: <project name="testxml" default="build"> <imp

我有一个ant脚本,它导入了其他脚本,这些脚本导入了其他脚本,这些脚本指向可以进行定义的地方网络

ant能否像maven的
帮助:effective pom
那样导入所有定义并输出一个文件


我想将此作为输出文件添加到我的构建中,以使调试更容易。

您可以创建另一个目标,该目标将创建此类文件。例如,它可以如下所示:

main build.xml,它可以完成一些工作,还可以生成有效的构建:

<project name="testxml" default="build">

    <import file="build1.xml" />
    <import file="build2.xml" />

    <target name="build">
        <echo>build project</echo>
    </target>

    <target name="effective.build">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="C:\Program Files (x86)\groovy-2.1.4\embeddable\groovy-all-2.1.4.jar" />
        <groovy>
            def regex = ~/import file="(.*)"/
            def buildXmlContent = new File('build.xml').text
            new File('build.xml').eachLine {
                line -> regex.matcher(line).find() {
                    def file = new File(it[1])
                    if (file.exists()) {
                        def replacement = file.getText().replaceAll(/&lt;project.*/, '').replaceAll(/&lt;\/project.*/, '')
                        buildXmlContent = buildXmlContent.replaceFirst(/&lt;import.*/, replacement)
                    }
                }
            }
            new File('build.effective.xml') &lt;&lt; buildXmlContent
        </groovy>
    </target>

</project>
为此,我选择了groovy(因为我实际上学习了它),但您可以用另一种语言创建它。您还可以将此groovy代码编译为ant任务,并将其用作新任务,例如
。我的例子并不完美,但它展示了一种解决方案

<project name="testxml2" default="build">
    <target name="clean">
        <echo>clean project</echo>
    </target>
</project>

<project name="testxml1" default="build">
    <target name="test">
        <echo>test project</echo>
    </target>
</project>
<project name="testxml" default="build">


    <target name="test">
        <echo>test project</echo>
    </target>


    <target name="clean">
        <echo>clean project</echo>
    </target>


    <target name="build">
        <echo>build project</echo>
    </target>

    <target name="effective.build">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="C:\Program Files (x86)\groovy-2.1.4\embeddable\groovy-all-2.1.4.jar" />
        <groovy>
            import java.util.regex.Pattern

            def regex = ~/import file="(.*)"/
            def buildXmlContent = new File('build.xml').text
            new File('build.xml').eachLine {
                line -> regex.matcher(line).find() {
                    def file = new File(it[1])
                    if (file.exists()) {
                        def replacement = file.getText().replaceAll(/&lt;project.*/, '').replaceAll(/&lt;\/project.*/, '')
                        buildXmlContent = buildXmlContent.replaceFirst(/&lt;import.*/, replacement)
                    }
                }
            }
            new File('build.effective.xml') &lt;&lt; buildXmlContent
        </groovy>
    </target>

</project>