命令只运行Maven中定义的一个特定测试插件

时间:2010-01-08 13:03:15

标签: testing maven-2 command-line

我有一个Maven POM文件,其中包含一个在测试阶段运行的插件。为了执行该插件而不是该阶段的所有插件,我必须通过什么命令行参数传递mvn?我也在尝试执行一个特定的ant-run插件,如下所示:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <dependencies>
          <dependency>
            <groupId>com.googlecode.jslint4java</groupId>
            <artifactId>jslint4java-ant</artifactId>
            <version>1.3.3</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>jslint</id>
            <phase>test</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <ant antfile="${basedir}/jslint.xml">
                  <property name="root" location="${basedir}" />
                  <target name="jslint" />
                </ant>
              </tasks>
            </configuration>
          </execution>
        </executions>
    </plugin>

感谢。

1 个答案:

答案 0 :(得分:2)

以下列形式指定完全合格的目标:

mvn groupID:artifactID:version:goal

例如:

mvn sample.plugin:maven-hello-plugin:1.0-SNAPSHOT:sayhi

编辑:我正在修改我的答案,以涵盖初始问题的更新和OP的评论。

我不会涵盖所有细节,但是,它是antrun插件的特殊情况,你可以运行:

mvn antrun:run

但是现在你已经更新了这个问题,我知道事情比我最初想的要复杂一些,我不认为这会有效。我的意思是,调用mvn antrun:run不会失败,但它不会获取configuration execution test阶段的 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <dependencies> <dependency> <groupId>com.googlecode.jslint4java</groupId> <artifactId>jslint4java-ant</artifactId> <version>1.3.3</version> </dependency> </dependencies> <configuration> <tasks> <ant antfile="${basedir}/jslint.xml"> <property name="root" location="${basedir}" /> <target name="jslint" /> </ant> </tasks> </configuration> </plugin>

我能想到的唯一(丑陋)解决方案是在特定配置文件中添加另一个maven-antrun-plugin配置,如下所示:

antrun:run

在调用mvn antrun:run -Pmyprofile-for-antrun 时使用此个人资料:

{{1}}