How can maven be configured to support this type of workflow:
One Time Setup Invoke maven to do one time setup of a developers machine such as
- Create a custom version of tomcat configured for this application
- Create a local postgres database on the developers machine
- load sample data into the database
- run a junit test to configure other resources needed to run the application
Integration Tests Invoke maven to do run integration tests which should do the following
- Create an integration test db
- setup the db
- Run command line integration tests against the db
- Run a test version of tomcat with the application in it
- Run command line junit tests that test the restful services exposed by the application
Release Build Invoke maven to do a release build of the system
- do all the steps for an integration test
- generate resources and configurations that are used on the server rather than production
- deposit the end result in a git repo, commit, and push the changes to production
Test Build Invoke maven to do a test build of the system
- do all the steps of a release build but configure the test release package with test server configuration
The main thing I am struggling with is that maven has a single build life-cycle with a well defined sequence of phases not sure if the workflow I want to build is a good fit for maven.
Can maven be configured for this type of workflow? If yes what are the key features of maven that allow for the different configurations of the four main ways that I want to use maven?
Update What I mean by this workflow, is that I want to be able to do something like
mvn setup
mvn integration
mvn prod-release
mvn test-release
I know the above example look like ant, I am long time ant user and total noob with maven.
You could setup Maven to do all that…
You probably would use (shock horror) profiles to achieve some of this…
BUT you don’t want to do that
You are following ANT style thinking… if you like that style of thinking then use ANT or Gradle and be happy.
If you want to follow the Maven way, then you will solve the problem differently.
Coming from the Maven way, here are my thoughts:
Why do you need one-time setup? I usually have a
runprofile that dynamically provisions the correct application server and starts it with the App deployed, tearing down everything afterwards when I hit^C. Typically this involves starting up a database server or two… hence things I have developed like the cassandra-maven-plugin. That way when I am working on a different project (which could be in 10 minutes time) I don’t have to worry about background database servers eating up all my laptop’s ram.Integration tests are actually trivial when you have the above working… in fact I created the Maven Failsafe Plugin to make it easy to have plugin execution tied to the appropriate phases for integration testing. The Maven convention is to have a profile called
run-itsfor running integration tests.Release builds being different from test builds… ugh! You should be building environment agnostic artifacts. Have them pick up their configuration from the environment they are deployed in. That removes the worry that something has changed between the “test” build and the “production” build. If you really need to bundle the config, then I usually would resort to a separate module for taking the agnostic artifact and rebundling with the required configuration. That way it is easy to prove that you have a reproducible transformation and that nothing has changed inbetween what went to QA vs what is going to Ops.
I always make the release builds include the integration testing.
So typically I have my projects such that
will fire up the application starting from zero. Hitting ^C will tear everything back down again, and
mvn cleanor in extreme situations if I have a more complex setup process and need some cachingmvn post-clean(think really clean) will remove anything that therunprofile put into playTo run the integration tests I typically do
To make a release I typically do
That is (in my view) the ideal way of handling the above steps you need.
HTH.
BTW I have not had to use PostgreSQL specifically (typically my integration tests and
runprofile can get away with a pure java database such as derby or hsqldb and because the artifacts are environment agnostic it is easy to have the integration test/dev flyweight app server inject the correct JDBC url) so you may hit some issues with regard to PostgreSQL