I am trying to figure out how to setup continuous integration using maven.
What I want is:
- Check for new stuff in SVN
- If changes are detected, check them out
- Build and deploy
I think all of this can be pushed into some shell script to make it be invoked by cron. Thus we will have automated continuous integration (nightly builds, for example)
I know that maven has SCM plugin for working with version control systems, but I don’t know how to make it check for changes in repository and based on the results launch checkout.
So I am asking the audience 🙂
PS I forget to mention – I am NOT INTERESTING in any of existing applications! They are too heavy for my VPS server. Please do not advise them
I’d recommend using a recognised CI tool for managing this as there is more to CI than just the build.
But if you are determined to roll your own, you can use some of the goals from the maven-scm-plugin and capture the output.
Assuming you have a local copy of the project so you’ve access to the pom, you can run the status command to check for changes, and parse the output checking for any changes
The goal to use is:
If you see any changed files, then you can check out the changes and invoke your build.
Beware though, there is a bug in maven-scm-provider-svnlink text that means changed files can be skipped! You may be better invoking Subversion directly and parsing its output.
For example the following will clear up a previous build, check out any changed content and then run the deploy goal.
If you don’t have a working copy of the project, you can use the scm:bootstrap goal to obtain it. If you set up some properties in a pom you can reuse the pom to bootstrap multiple projects.
For example the pom below can bootstrap any project if you pass the appropriate command line arguments to it:
To make Maven work with subversion you need to configure the scm section of the POM:
As an alternative for polling for changes, consider adding a hook to subversion so that the build is triggered when a change is made. There’s another question that can give you a pointer on doing that.