【问题标题】:java maven exec-maven-plugin not executing on mvn clean installjava maven exec-maven-plugin 未在 mvn clean install 上执行
【发布时间】:2014-07-04 10:40:54
【问题描述】:

上一个问题的跟进: Maven run class before test phase: exec-maven-plugin exec:java not executing class.

我在一个 jenkins 盒子上运行 jUnit4 测试,用 maven 构建。在构建的测试阶段之前,我需要运行一个特定的 main-method java 程序。目的是在测试运行之前恢复测试数据库。

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

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

但不适用于:
mvn -X -e install
-- 或 --
mvn -X -e clean install

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>

生命周期默认值: 我没有对 maven 的生命周期感到厌烦。日志报告为:

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

【问题讨论】:

    标签: java maven jenkins exec-maven-plugin


    【解决方案1】:

    &lt;pluginManagement&gt; 下定义您的插件后,您实际上是在告诉 Maven,当您调用该插件时,您将在整个项目中使用哪个版本的插件。我通常希望 &lt;pluginManagement&gt; 标签出现在父 pom 中。

    要调用插件 - 只需输入 &lt;plugins/&gt; 元素。它可能继承也可能不继承自

    所以要使用插件,你只需要通过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>
    

    没有任何&lt;pluginManagement&gt;标签

    【讨论】:

    • 你好,艾希什。你在它上面: 正在扼杀它。
    【解决方案2】:

    Ashish 正在努力:&lt;pluginManagement&gt; 正在扼杀它。

    由于 Eclipse 和 m2e 中的问题,我认为我需要 &lt;pluginManagement&gt;。原来 m2e 的人有一个解决方案(一个非常复杂的解决方案)。

    见:

    How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds

    -- 和--

    http://wiki.eclipse.org/M2E_plugin_execution_not_covered

    如果你遇到这种情况,祝你好运!

    【讨论】:

    • 想知道为什么这被否决了。我不关心代表点(无论如何),但如果我知道这篇文章有什么问题,我可以成为一个更好的公民。
    • 我同意,我不确定为什么有人会投反对票,并且不告诉您如何改进它。我赞成至少从否定中得到你的答案(目前),因为我认为你的回答是彻底和有帮助的。谢谢!
    猜你喜欢
    • 2021-07-03
    • 2012-03-13
    • 2014-04-23
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2011-01-12
    • 2020-01-25
    • 2012-11-13
    相关资源
    最近更新 更多