带有顺序蚂蚁contrib的maven antrun无法运行
-
09-10-2019 - |
题
我们有一个特殊的例程,将子文件夹中的文件爆炸为扩展名,将复制并将其列入单个扩展文件中。对于这种特殊方法,我想使用 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>
错误
[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
其他提示
因此,我浪费了至少一个小时以在下面找到错误的提示...
我使用Maven3和上述所述的其余部分,但我必须使用 maven.dependency.classpath
代替 maven.plugin.classpath
呢否则,Maven找不到贡献任务。希望这对任何人都有帮助。
浪费了2个小时并阅读了太多答案,这就是我需要检查的
我用这个打印了所有的Maven Class Paths
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
并检查了哪个类Path包含Antrib Jar文件。所以我改变了 classpathhref
至 maven.runtime.classpath
从 maven.plugin.classpath
。所以我的 taskdef
是
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.runtime.classpath" />
和依赖项
<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>
我也浪费了几个小时,因为Antcontrib for
找不到任务。
最后,我发现 for
未定义的任务 antcontrib.properties
, , 但在 antlib.xml
!
antcontrib.properties
是蚂蚁前1.6做事的方式 - 现代方法是使用 antlib.xml
.
所以,这是一个 Maven 3.5, 蚂蚁1.8, ,工作示例:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<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>
</dependencies>
<execution>
<id>deploy_to_distrib_folder</id>
<phase>package</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<macrodef name="deploy_extra_dir">
<attribute name="dir" />
<sequential>
<basename property="basename" file="@{dir}" />
<sync todir="${outputDir}/${basename}">
<fileset dir="@{dir}" />
</sync>
<var name="basename" unset="true" />
</sequential>
</macrodef>
<for param="dir">
<path>
<dirset dir="${project.build.directory}/maven-shared-archive-resources" includes="*" />
</path>
<sequential>
<deploy_extra_dir dir="@{dir}" />
</sequential>
</for>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</plugin>
希望这可以帮助!
不隶属于 StackOverflow