具有顺序ant-contrib的Maven antrun无法运行

Chr*_*wes 7 ant maven-2 maven-3 maven-antrun-plugin

我们有一个特殊的例程来将子文件夹中的文件分解为扩展,这些扩展将被复制并放入单个扩展文件中.对于这种特殊的方法,我想使用maven-antrun-plugin,通过dirset的顺序迭代和jar包装,我们需要库ant-contrib.

即将推出的插件配置失败并显示错误.我错误配置了什么?谢谢.

插件配置

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
          <for param="extension">
            <path>
              <dirset dir="${basedir}/src/main/webapp/WEB-INF/resources/extensions/">
                <include name="*" />
              </dirset>
            </path>

            <sequential>
              <basename property="extension.name" file="${extension}" />
              <echo message="Creating JAR for extension '${extension.name}'." />
              <jar destfile="${basedir}/target/extension-${extension.name}-1.0.0.jar">
                <zipfileset dir="${extension}" prefix="WEB-INF/resources/extensions/${extension.name}/">
                  <include name="**/*" />
                </zipfileset>
              </jar>
            </sequential>
          </for>
        </target>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
      <version>1.0b3</version>
      <exclusions>
        <exclusion>
          <groupId>ant</groupId>
          <artifactId>ant</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.ant</groupId>
      <artifactId>ant-nodeps</artifactId>
      <version>1.8.1</version>
    </dependency>
  </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project extension-platform: An Ant BuildException has occured: Problem: failed to create task or type for
[ERROR] Cause: The name is undefined.
[ERROR] Action: Check the spelling.
[ERROR] Action: Check that any custom tasks/types have been declared.
[ERROR] Action: Check that any <presetdef>/<macrodef> declarations have taken place.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Run Code Online (Sandbox Code Playgroud)

小智 10

因此我浪费了至少一个小时的时间才能找到错误的一点提示......

我使用maven3和其余如上所述,但我必须使用maven.dependency.classpath 而不是maven.plugin.classpath!否则maven将找不到contrib任务.希望这可以帮助任何人.


mar*_*ton 9

看起来你错过了声明ant-contrib任务所需的taskdef,因此Ant知道它们,因此这部分错误消息:

Problem: failed to create task or type for
Run Code Online (Sandbox Code Playgroud)

(如果失败的任务'for'- 被引用可能会更清楚一些.)

添加taskdef的一种方法是在for循环之前立即插入:

<target>
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpathref="maven.plugin.classpath" />
    <for param="extension">
    ...
Run Code Online (Sandbox Code Playgroud)