java - How to stop Maven's verify phase rebuilding the artifact? -
imagine java project built using maven have:
- some fast-running unit tests that:
- developers should run before committing
- my ci server (hudson, fwiw) should run upon detecting new commit, giving instant feedback in case of failures
- some slow-running automated acceptance tests that:
- developers can run if choose, e.g. reproduce , fix failures
- my ci server should run after running unit tests
this seems typical scenario. currently, i'm running:
- the unit tests in "test" phase
- the acceptance tests in "verify" phase
there 2 ci jobs configured, both pointing project's vcs branch:
- "commit stage", runs "mvn package" (compile , unit test code, build artifact), if successful, triggers:
- "automated acceptance tests", runs "mvn verify" (set up, run, , tear down acceptance tests)
the problem job 2 unit tests , builds artifact-under-test on again (because verify phase automatically invokes package phase). undesirable several reasons (in decreasing importance):
- the artifact created job 2 might not identical created job 1 (e.g. if there has been new commit in meantime)
- lengthens feedback loop developer made commit (i.e. takes longer them find out broke build)
- wastes resources on ci server
so question is, how can configure job 2 use artifact created job 1?
i realise have 1 ci job runs "mvn verify", create artifact once, want have separate ci jobs described above in order implement farley-style deployment pipeline.
in case helps anyone, here's full maven 2 pom of "project 2" in accepted answer:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.example.cake</groupid> <artifactid>cake-acceptance</artifactid> <version>1.0</version> <packaging>jar</packaging> <name>cake shop acceptance tests</name> <description> runs automated acceptance tests cake shop web application. </description> <build> <plugins> <!-- compiler --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.3.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <!-- suppress normal "test" phase; there's no unit tests --> <plugin> <artifactid>maven-surefire-plugin</artifactid> <version>2.5</version> <configuration> <skiptests>true</skiptests> </configuration> </plugin> <!-- cargo (starts , stops web container) --> <plugin> <groupid>org.codehaus.cargo</groupid> <artifactid>cargo-maven2-plugin</artifactid> <version>1.0.5</version> <executions> <execution> <id>start-container</id> <phase>pre-integration-test</phase> <goals> <goal>start</goal> </goals> </execution> <execution> <id>stop-container</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> <configuration> <!-- don't wait ctrl-c after starting container --> <wait>false</wait> <container> <containerid>jetty7x</containerid> <type>embedded</type> <timeout>20000</timeout> </container> <configuration> <properties> <cargo.servlet.port>${http.port}</cargo.servlet.port> </properties> <deployables> <deployable> <groupid>${project.groupid}</groupid> <artifactid>${target.artifactid}</artifactid> <type>war</type> <properties> <context>${context.path}</context> </properties> </deployable> </deployables> </configuration> </configuration> </plugin> <!-- failsafe (runs acceptance tests) --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-failsafe-plugin</artifactid> <version>2.6</version> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> <configuration> <includes> <include>**/*test.java</include> </includes> <skiptests>false</skiptests> </configuration> </plugin> </plugins> </build> <dependencies> <!-- add tests' dependencies here, e.g. selenium or sahi, "test" scope --> <dependency> <!-- artifact under test --> <groupid>${project.groupid}</groupid> <artifactid>${target.artifactid}</artifactid> <version>${target.version}</version> <type>war</type> </dependency> </dependencies> <properties> <!-- artifact under test --> <target.artifactid>cake</target.artifactid> <target.version>0.1.0-snapshot</target.version> <context.path>${target.artifactid}</context.path> <http.port>8081</http.port> <java.version>1.6</java.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> </project>
note though "tests" project doesn't create artifact, has use kind of packaging (i used "jar" here), otherwise no tests run in verify phase.
try 2 maven projects. first 1 contains build , unit tests. install artifacts in local repository. second job runs second maven project declares artifacts of first project dependencies , runs functional tests.
not sure if scenario described possible, think is.
for quick improvement can bypass unit test -dmaven.test.skip=true
. if pass revision number of code in scm second job, should able checkout same source code.
you can check clone workspace scm plugin. might offer additional options.
Comments
Post a Comment