我正在尝试设置maven,以便在我的web项目中的目录上执行较少的CSS预处理器。基本流程是:
<foreach/>遍历一个目录,找到所有.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]看来Ant中的某些内容导致它尝试读取POM文件,可能是为了寻找目标。我看到这两个目标都被生成到文件target/antrun/buil-main.xml和target/antrun/buil-processLessFile.xml中,因此这是它应该查看的目录。
发布于 2012-05-24 19:27:32
ant插件似乎不支持多个目标部分的声明。您可以检查生成的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>发布于 2012-05-24 06:36:14
您知道-maven-plugin,我认为它应该解决您的问题。
https://stackoverflow.com/questions/10728645
复制相似问题