简体   繁体   English

java maven exec-maven-plugin没有在mvn clean install上执行

[英]java maven exec-maven-plugin not executing on mvn clean install

Follow-up to a previous question: Maven run class before test phase: exec-maven-plugin exec:java not executing class . 后续问题的后续: Maven在测试阶段之前运行类:exec-maven-plugin exec:java不执行类

I am running jUnit4 tests, built with maven, on a jenkins box. 我在jenkins盒子上运行jUnit4测试,用maven构建。 I need to run a specific main-method java program before before the test phase of my build. 我需要在构建的测试阶段之前运行特定的main方法java程序。 The intent is to restore a test database before the tests run. 目的是在测试运行之前恢复测试数据库。

If I run the exact phase this exec is assigned to, my class executes as expected; 如果我运行了这个exec分配给的确切阶段,我的类按预期执行; but when I run the whole build, my class does not execute: 但是当我运行整个构建时,我的类不会执行:

Specifically, it runs with: 具体来说,它运行:
mvn -X exec:java generate-test-resources

But does not run with: 但不运行:
mvn -X -e install
-- or -- - 要么 -
mvn -X -e clean install

pom.xml: My pom.xml file includes: pom.xml:我的pom.xml文件包括:

<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>

Lifecycle default: I have not futzed with maven's lifecycle. 生命周期默认:我还没有看到maven的生命周期。 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
]

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. 使用<pluginManagement>下定义的插件,您实际上在告诉maven在调用插件时将在整个项目中使用哪个插件版本。 I would normally expect the <pluginManagement> tag to be present in the parent pom. 我通常希望<pluginManagement>标记出现在父pom中。

To invoke the plugin - simply put the <plugins/> element. 要调用插件 - 只需输入<plugins/>元素即可。 It may or may not be inherited from a 它可能会也可能不会从a继承

Hence to use the plugin, you just need to invoke the plugin by putting 因此,要使用该插件,您只需要通过put来调用插件

<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>

without any <pluginManagement> tag 没有任何<pluginManagement>标记

Ashish was on to it: <pluginManagement> was killing it. Ashish接着说: <pluginManagement>正在杀死它。

I thought I needed <pluginManagement> because of problems in Eclipse and m2e. 我认为我需要<pluginManagement>因为Eclipse和m2e存在问题。 Turns out the m2e guys had a solution (a very complicated solution). 原来m2e的人有一个解决方案(一个非常复杂的解决方案)。

See: 看到:

How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds 如何解决Spring Data Maven Builds的“生命周期配置未涵盖的插件执行”

-- and -- - 和 -

http://wiki.eclipse.org/M2E_plugin_execution_not_covered http://wiki.eclipse.org/M2E_plugin_execution_not_covered

Good luck, if you run into this! 祝你好运,如果遇到这个!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM