sfussenegger
sfussenegger

Reputation: 36095

How to create a patched build with Maven?

I was wondering if there is a standard way (i.e. a plugin) to apply a set of patches during a Maven build. Patching the code base in a dedicated step before building is getting tedious as soon as you have different builds or generated sources.

To give an example, this script should deploy 3 different versions from a fresh SVN checkout:

#!/bin/bash

# checkout project
svn checkout http://example-project.googlecode.com/svn/tag/v1_0 example-project-read-only
cd example-project-read-only

# build example-project-1.0
mvn deploy

# build example-project-1.0-a3
mvn -Dmaven.patch.dir=/path/to/patchesA -Dmaven.patch.buildSuffix=a3 clean patch:patch deploy

# build example-project-1.0-b0
mvn -Dmaven.patch.dir=/path/to/patchesB -Dmaven.patch.buildSuffix=b0 clean patch:patch deploy

Currently I'm doing similar things with another build script I'd like to get rid of. Therefore I'm considering to write such a plugin if it's not available yet. (Maybe with dedicated patch artifacts for easy distribution as an added bonus?)

Upvotes: 3

Views: 2937

Answers (2)

Ken Liu
Ken Liu

Reputation: 22914

The maven patch plugin might help.

The Patch Plugin has a single goal that can apply either a single declared patch or a directory of patches. Application of an entire patch directory can be configured with various patch-inclusion, -exclusion, and -ordering options:

Upvotes: 3

Cliff
Cliff

Reputation: 11248

I haven't heard of any such plugin. However I imagine that you could do something with profiles that applied patches and conditionalized the build dir. Sounds interesting.

Upvotes: 0

Related Questions