Maven3 antrun:无法创建任务或键入replaceregexp

时间:2011-06-22 19:14:36

标签: ant replace maven-3

我试图用maven编写一个简单的任务

<plugin>
 <artifactId>maven-antrun-plugin</artifactId>
 <version>1.3</version>
 <executions>
  <execution>
    <phase>install</phase>
    <goals>
        <goal>run</goal>
    </goals>
    <configuration>
    <tasks>
     <replaceregexp file="dir=target/liquibase/*.sql" match="**DATABASECHANGELOGLOCK**" 
             replace="" byline="true" />
        </tasks>
    </configuration>
    </execution>
  </executions>
</plugin>

当我运行时,我得到了

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (default) on project Tik
[ERROR] Cause: the class org.apache.tools.ant.taskdefs.optional.ReplaceRegExp was not found.
[ERROR] This looks like one of Ant's optional components.
[ERROR] Action: Check that the appropriate optional JAR exists in
[ERROR] -ANT_HOME\lib
[ERROR] -the IDE Ant configuration dialogs
[ERROR]
[ERROR] Do not panic, this is a common problem.
[ERROR] The commonest cause is a missing JAR.
[ERROR]
[ERROR] This is not a bug; it is a configuration problem
[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

我已经包含了antant-nodeps个依赖项,但无法让它运行,并且谷歌搜索没有任何帮助。

有人有解决方案吗?

提前致谢。

2 个答案:

答案 0 :(得分:8)

我正在写这封信以防万一有人遇到这个问题

问题在于maven并不关心ANT_HOME或其他什么。必须在antrun插件中声明依赖关系。

所以我将pom.xml改为:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <dependencies>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.6.5</version>
        </dependency>
    </dependencies>
    <executions><execution>...</execution></executions>
</plugin>

答案 1 :(得分:1)

maven-antrun-plugin版本1.8不再存在此问题。它的依赖关系指向更新版本的Ant,因此您不再需要在pom中为插件声明添加依赖项。