Maven is close to ubiquitous in the world of enterprise Java, and the Maven dependency ecosystem is the de facto industry standard. However, the traditional Maven build and release strategy, based on snapshot versions and carefully planned releases, is difficult to reconcile with modern continuous delivery practices, where any commit that passes a series of quality-control gateways can qualify as a release. How can teams using the standard Maven release process still leverage the benefits of continuous delivery? This presentation discusses strategies that can be used to implement continuous delivery solutions with Maven and demonstrates one such strategy using Maven, Jenkins, and Git.
23. The Maven lifecycle
compile
test-compile
test
package
integration-test
verify
install
deploy
24. The Maven lifecycle
Compile and unit test mvn test compile
test-compile
test
Integration tests mvn verify compile
test-compile
test
package
integration-test
verify
25. The Maven lifecycle
Compile and unit test mvn test compile
test-compile
test
compile
test-compile
Integration tests mvn verify test
package
integration-test
verify
Deploy to repository compile
mvn deploy
test-compile
test
package
integration-test
verify
deploy
26. The Maven Release Process
1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
mvn release
1.0.0
27. The Maven Release Process
mvn release:prepare
• Check that there are no uncommitted changes in the sources
• Check that there are no SNAPSHOT dependencies
• Change the version in the POMs from x-SNAPSHOT to a new version (you
will be prompted for the versions to use)
• Transform the SCM information in the POM to include the final destination
of the tag
• Run the project tests against the modified POMs to confirm everything is in
working order
• Commit the modified POMs
• Tag the code in the SCM with a version name (this will be prompted for)
• Bump the version in the POMs to a new value y-SNAPSHOT (these values
will also be prompted for)
• Commit the modified POMs
28. The Maven Release Process
mvn release:prepare
compile
test-compile
test
package 1.0.0
integration-test
verify 1.0.1-SNAPSHOT
1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
29. The Maven Release Process
mvn release:perform
compile
test-compile
test
1.0.0 package
integration-test
verify
install
deploy
1.0.0
30. The Maven Release Process
Maven: You build a new release when
a snapshot build is good enough
Continuous Delivery: Any
build is a potential release
42. Run code coverage with the integration tests
compile
test-compile
Integration tests mvn verify test
package
integration-test
verify
Test coverage mvn cobertura
compile
test-compile
Duplication! test
package
integration-test
cobertura
Creates its own instrumented JAR files
46. Run code coverage with the integration tests
Integration tests/test compile
test-compile
mvn install test
coverage package
integration-test
verify
Uninstrumented JAR
Coverage checks and report
52. Take code quality seriously
Pick and choose your metrics
Code quality metrics
mvn pmd:check
mvn findbugs:check
mvn checkstye:checkstyle
Fail the build if there are violations
53. Avoid the Maven Release Plugin
Don’t sweat the version numbers
54. Developers always work on a SNAPSHOT version
1.0-SNAPSHOT
This number is pretty arbitrary
55. Jenkins sets a release candidate version at the
start of the build pipeline
1.0-SNAPSHOT
1.0.203
This number is a build counter
56. This version goes through the build pipeline
1.0.203
Unit tests
Acceptance tests
Code quality metrics
Deploy to TEST
57. This version goes through the build pipeline
1.0.203
1.0.204
1.0.205
Unit tests
Acceptance tests
Code quality metrics
Deploy to TEST
Acceptance Tests
1.0.203
1.0.204
1.0.205
58. Create a new release branch
Update the version number
Build and test release candidate
Did
it work?
No Yes
Drop release branch Push release branch
Notify everyone Deploy release candidate
59. Create a new release branch
Update the version number
Build and test release candidate 1.0.203
Did
it work?
No Yes
Drop release branch Push release branch
Notify everyone Deploy release candidate
60. Create a new release branch
Update the version number
Versions Plugin
Build and test release candidate
mvn versions:set -DnewVersion=1.0.203
Did
it work?
No Yes
Drop release branch Push release branch
Notify everyone Deploy release candidate
61. Create a new release branch
Update the version number
Build and test release candidate
Did
mvn verify ...
it work?
No Yes
Drop release branch Push release branch
Notify everyone Deploy release candidate
80. initial-build
code-quality
Pass in the release we want to build against
deploy-to-test
acceptance-tests
deploy-to-uat
acceptance-tests
deploy-to-prod
81. initial-build
code-quality
deploy-to-test
Build from the release candidate branch
acceptance-tests
deploy-to-uat
acceptance-tests
deploy-to-prod
86. initial-build
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
What platform do we run the acceptance test against
acceptance-tests
deploy-to-prod
87. initial-build
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
What platform do we run the acceptance test against
acceptance-tests
deploy-to-prod
89. initial-build
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
What platform do we run the acceptance test against
acceptance-tests
deploy-to-prod
90. initial-build
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
What platform do we run the acceptance test against
acceptance-tests
deploy-to-prod
92. initial-build
Copy the WAR file from the initial build...
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
...and deploy it to UAT
acceptance-tests
deploy-to-prod
93. A build promotioninitial-build deploy to production
process to
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
acceptance-tests
deploy-to-prod
94. A build promotioninitial-build deploy to production
process to
code-quality
deploy-to-test
acceptance-tests
deploy-to-uat
acceptance-tests
deploy-to-prod