Better Maven Deploy

mvn deploy has two major issues:

  1. If the project has several modules and the build fails in the middle, you will end up with a repository that is a mix of old and new modules.
  2. The POM must have the correct values in the distributionManagement element.

The former can break builds for your colleagues, the latter means you have to edit the POM file. Not a big deal – unless the POM file comes from an external source, say, an OSS project. If you edit it, you need to maintain the changes. But it gets ugly when your changes are committed to the external project.

The following script solves both problems. In a nutshell, it copies the POM, removes any existing distributionManagement elements, adds the ones you want and then builds using the new, temporary POM. If the build succeeds, the temporary POM is deleted.

The build itself is split into two steps. The first step does a local build, the second build skips tests and only uploads the results. It does run the compilers again but since the code was already built a few seconds ago, this shouldn’t be an issue.

Shell script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s