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

前端 未结 5 1868
太阳男子
太阳男子 2020-12-31 21:15

Imagine a Java project built using Maven for which I have:

  • some fast-running unit tests that:
    • developers should run before committing
    • my CI s
相关标签:
5条回答
  • 2020-12-31 21:54

    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.

    0 讨论(0)
  • 2020-12-31 21: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.

    0 讨论(0)
  • 2020-12-31 21:55

    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.

    0 讨论(0)
  • 2020-12-31 21:56

    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>
    
    0 讨论(0)
  • 2020-12-31 22:08

    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.

    0 讨论(0)
提交回复
热议问题