How to stop Maven's verify phase rebuilding the artifact?

為{幸葍}努か 提交于 2019-11-30 07:35:55

Try two maven projects. The first one contains the build and unit tests. You install the artifacts in your local repository. The second job runs the second maven project which declares the artifacts of the first project as dependencies and runs the functional tests.

Not sure if the scenario I just described is possible, but I think it is.

For a quick improvement you can bypass the unit test with -Dmaven.test.skip=true. If you pass the revision number of your code in your scm to the second job, you should be able to checkout the same source code.

You can also check into the Clone Workspace SCM plugin. This might offer you some additional options.

I know it's been a long time, but this is well-indexed and none of the answers do what was asked, but I found something that works:

mvn failsafe:integration-test

This runs the tests directly, without going through all the intermediate steps of building the project. You may want to add failsafe:verify after it.

So my question is, how can I configure job 2 to use the artifact created by job 1?

You can't.

You don't need to. The Maven Build lifecycle is setup in a way that sounds like it will meet your needs. The test lifecycle will only run the fast junits. Package build your end state without running the verification.

You only need one CI job. When the CI runs your the maven deploy/install life cycle, if the junits fail the build fails, the verification scripts will not execute.

You can define a Maven profile that will be used to execute only the integration tests. I do this a lot.

Something like this:

<profiles>
    <profile>
        <id>integration</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId><version>2.17</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId><version>2.4</version>
                    <configuration>
                        <outputDirectory>/tmp</outputDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

You would invoke this with:

mvn verify -Pintegration

Unfortunately the WAR plugin can't be skipped, but you can send its output to somewhere out of the way (I've used /tmp). If you really want to save milliseconds, you could also make it ignore the web resources (except web.xml, it won't work without that).

You can also use the profile to skip any other plugins that you might be running, eg the assembly plugin, Cobertura, PMD, etc.

Noam Manos

Maven profile that executes only the integration tests (as suggested here) is not sufficient. You also need to make sure that the configuration of maven-compiler-plugin has useIncrementalCompilation = false. Running the profile this way, will not automatically re-compile, e.g.:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!