Web プロジェクトのディレクトリで LESS CSS プリプロセッサを実行するように Maven をセットアップしようとしています。基本的な流れは次のとおりです。
- Maven は maven-antrun-plugin を呼び出します。
- Ant-contrib
<foreach/>
はディレクトリをループし、すべての .less ファイルを見つけてターゲットを呼び出します。 - ターゲットは、ファイルを変換する LESS を実行する Rhino を実行します。
これを行うには、次の 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/build-main.xml および target/antrun/build-processLessFile.xml に生成されていることがわかります。そのため、それが検索対象のディレクトリになります。