-->

在Maven的antrun-插件调用的foreach(Calling foreach in mave

2019-07-29 12:44发布

我试图建立行家在我的web项目执行上的一个目录中LESS CSS预处理程序。 基本流程是:

  1. Maven的调用Maven的antrun的插件。
  2. 蚂蚁的contrib <foreach/>遍历目录,发现所有的.LESS文件并调用目标。
  3. 目标执行犀牛,它执行LESS该文件转换。

要做到这一点,我有以下XML:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <target name="processLessFile">
                            <!-- ... -->
                        </target>
                        <target name="main">
                            <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
                            <property name="css.dir" location="src/main/webapp/css"/>
                            <foreach param="file" target="processLessFile">
                                <fileset dir="${css.dir}">
                                    <filename name="**/*.less" />
                                </fileset>
                            </foreach>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>ant</groupId>
                    <artifactId>ant-contrib</artifactId>
                    <version>1.0b2</version>
                </dependency>
            </dependencies>
        </plugin>

我现在遇到的问题是,“主”的目标开始执行,但随后未能在<foreach>

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project model-web-project: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /Users/.../pom.xml:4: Unexpected element "{http://maven.apache.org/POM/4.0.0}project" {antlib:org.apache.tools.ant}project
[ERROR] around Ant part ...<foreach param="file" target="processLessFile">... @ 6:50 in /Users/.../target/antrun/build-main.xml
[ERROR] -> [Help 1]

看来,东西蚂蚁导致它尝试读取POM文件,可能是在寻找目标。 我看到这两个指标均生成到目标文件/ antrun /集结main.xml中和目标/ antrun /集结processLessFile.xml所以这是它应该寻找在目录中。

Answer 1:

蚂蚁插件似乎并不支持多个目标部分的声明。 您可以检查生成的Ant脚本来看看我说的:

target/antrun/build-main.xml

挖掘更深的插件文件规定如下:

它不是这个插件提供污染POM的手段的意图,因此它鼓励所有Ant任务移动到一个build.xml文件,只是使用Ant的任务,把它从POM。

难听的话,但建议十分合理。 我建议你移动你的ANT逻辑放到一个专门的文件,并调用它,如下所示:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                            <ant antfile="${basedir}/src/main/ant/build.xml"/>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


Answer 2:

您是知道的lesscss - Maven的插件 ,我认为应该解决您的问题。



文章来源: Calling foreach in maven-antrun-plugin