java maven exec-maven-plugin无法在mvn全新安装上执行 [英] java maven exec-maven-plugin not executing on mvn clean install

查看:152
本文介绍了java maven exec-maven-plugin无法在mvn全新安装上执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注上一个问题: 测试阶段之前的Maven运行类:exec-maven-plugin exec:java不执行类.

我正在jenkins盒子上运行用maven构建的jUnit4测试.在构建测试阶段之前,我需要运行特定的主方法Java程序.目的是在测试运行之前还原测试数据库.

I am running jUnit4 tests, built with maven, on a jenkins box. I need to run a specific main-method java program before before the test phase of my build. The intent is to restore a test database before the tests run.

如果我运行该exec分配给的确切阶段,则我的类将按预期执行;但是当我运行整个构建时,我的类不会执行:

If I run the exact phase this exec is assigned to, my class executes as expected; but when I run the whole build, my class does not execute:

具体说来,它运行于:
mvn -X exec:java generate-test-resources

Specifically, it runs with:
mvn -X exec:java generate-test-resources

但不能与以下内容一起运行:
mvn -X -e install
-或-
mvn -X -e clean install

But does not run with:
mvn -X -e install
-- or --
mvn -X -e clean install

pom.xml:我的pom.xml文件包括:

pom.xml: My pom.xml file includes:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>            
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>build-test-environment</id>
                    <phase>generate-test-resources</phase>          
                    <goals>
                        <goal>java</goal>           
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>main.java._tools.BuildTestEnvironment</mainClass>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

生命周期默认值: 我还不喜欢Maven的生命周期.日志报告为:

Lifecycle default: I have not futzed with maven's lifecycle. The log reports it as:

[DEBUG] Lifecycle default -> [
    validate,
    initialize,
    generate-sources,
    process-sources,
    generate-resources,
    process-resources,
    compile,
    process-classes,
    generate-test-sources,
    process-test-sources,
    generate-test-resources,
    process-test-resources,
    test-compile,
    process-test-classes,
    test,
    prepare-package,
    package,
    pre-integration-test,
    integration-test,
    post-integration-test,
    verify,
    install,
    deploy
]

推荐答案

使用在<pluginManagement>下定义的插件,实际上是在告诉maven在调用插件时将在整个项目中使用哪个版本的插件.我通常希望<pluginManagement>标签出现在父pom中.

With your plugin defined under the <pluginManagement>, you are actually telling maven which version of the plugin you will use throughout your project when you will invoke the plugin. I would normally expect the <pluginManagement> tag to be present in the parent pom.

要调用插件-只需放置<plugins/>元素.它可能会也可能不会从

To invoke the plugin - simply put the <plugins/> element. It may or may not be inherited from a

因此要使用该插件,您只需要通过插入即可调用该插件

Hence to use the plugin, you just need to invoke the plugin by putting

<plugins>
        <plugin>            
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>build-test-environment</id>
                    <phase>generate-test-resources</phase>          
                    <goals>
                        <goal>java</goal>           
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>main.java._tools.BuildTestEnvironment</mainClass>
            </configuration>
        </plugin>
    ...AnyOtherPlugin
    <plugins>

没有任何<pluginManagement>标记

这篇关于java maven exec-maven-plugin无法在mvn全新安装上执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆