5

Web プロジェクトのディレクトリで LESS CSS プリプロセッサを実行するように Maven をセットアップしようとしています。基本的な流れは次のとおりです。

  1. Maven は maven-antrun-plugin を呼び出します。
  2. Ant-contrib<foreach/>はディレクトリをループし、すべての .less ファイルを見つけてターゲットを呼び出します。
  3. ターゲットは、ファイルを変換する 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 に生成されていることがわかります。そのため、それが検索対象のディレクトリになります。

4

2 に答える 2

6

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-24T19:27:32.910 に答える
1

あなたはlesscss-maven-pluginを知っています。これで問題が解決すると思います。

于 2012-05-24T06:36:14.867 に答える