首页 > 解决方案 > 想在 maven 构建后使用 exec-maven-plugin 执行 java 类,而不管 maven 构建状态如何

问题描述

我正在clean install exec:javapom 中运行并使用以下配置

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    mainClass>com.integrated.file.GenerateReport</mainClass>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>

当 maven 构建为 Success 时,这工作正常,但不适用于失败。我希望这适用于任何构建状态。有什么建议么 ?

在下面分享完整的 POM

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.card.automation REST_API_AUTOMATION 0.0.1-SNAPSHOT api-automation UTF-8 1.8 1.8 4.1

    <maven-compiler-plugin.version>3.0</maven-compiler-plugin.version>
    <compilerVersion>3.3</compilerVersion>
    <storyTimeout>14400</storyTimeout>

    <maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
    <maven-reports-plugin.version>2.8</maven-reports-plugin.version>
    <dependency.locations.enabled>false</dependency.locations.enabled>
            </properties>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${maven-javadoc-plugin.version}</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>${maven-reports-plugin.version}</version>
        </plugin>
    </plugins>
</reporting>
<dependencies>


    <!-- https://mvnrepository.com/artifact/org.jbehave/jbehave-core -->
    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>4.1</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.2</version>
<!-- <executions> <execution> <phase>pre-integration-test</phase> <goals> 
    <goal>exec</goal> </goals> </execution> </executions> -->
            <configuration>
                <mainClass>com.mastercard.edw.integrated.batches.GenerateReport</mainClass>
                <cleanupDaemonThreads>false</cleanupDaemonThreads>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <compilerVersion>${compilerVersion}</compilerVersion>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
        <!-- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin> -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack-resources-core</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <properties>
                            <serenityReport>true</serenityReport>
                        </properties>
                        <outputDirectory>${project.build.directory}/jbehave/view</outputDirectory>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                        <excludes>**/*.class</excludes>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.jbehave</groupId>
                                <artifactId>jbehave-navigator</artifactId>
                                <version>${jbehave.core.version}</version>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-maven-plugin</artifactId>
            <version>${jbehave.core.version}</version>
            <executions>
                <execution>
                    <id>run-stories-as-embeddables</id>
                    <phase>integration-test</phase>
                    <configuration>
                        <testResources>
                            <testResource>
                                <directory>src/main/resources/config/devcloud/TestData/</directory>
                                <includes>
                                    <include>**/*.csv</include>
                                </includes>
                            </testResource>
                        </testResources>
                        <storyTimeoutInSecs>${storyTimeout}</storyTimeoutInSecs>
                        <threads>${jbehave.execution.threads}</threads>
                        <includes>
                            <include>**/TestJUnitStories.java</include>
                        </includes>
                        <skip>${jbehave.skip.tests}</skip>
                        <metaFilters>
                            <metaFilter>${meta.filter}</metaFilter>
                        </metaFilters>
                        <systemProperties>
                            <property>
                                <name>java.awt.headless</name>
                                <value>true</value>
                            </property>
                        </systemProperties>
                        <ignoreFailureInStories>true</ignoreFailureInStories>
                        <ignoreFailureInView>false</ignoreFailureInView>
                        <generateViewAfterStories>true</generateViewAfterStories>
                        <storyTimeoutInSecs>${storyTimeout}</storyTimeoutInSecs>
                        <verboseFailures>true</verboseFailures>
                    </configuration>
                    <goals>
                        <goal>run-stories-as-embeddables</goal>
                        <goal>unpack-view-resources</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.17</version>
                </dependency>

            </dependencies>

        </plugin>
        <plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>1.1.36</version>
            <dependencies>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                    <version>1.7.25</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> 
            <version>${maven.checkstyle.plugin.version}</version> <executions> <execution> 
            <id>validate</id> <phase>validate</phase> <configuration> <configLocation>checkstyle.xml</configLocation> 
            <encoding>${project.build.sourceEncoding}</encoding> <consoleOutput>false</consoleOutput> 
            <failsOnError>false</failsOnError> <linkXRef>false</linkXRef> </configuration> 
            <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> -->
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-dependency-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>unpack</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-checkstyle-plugin
                                    </artifactId>
                                    <versionRange>
                                        [3.0.0,)
                                    </versionRange>
                                    <goals>
                                        <goal>check</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</project>

标签: javamaven

解决方案


推荐阅读