Saturday, March 16, 2013

Bossy Maven

The nagging issue I have with Maven right now is that if you want the Maven version and the project version to be in sync, and you want to follow the DRY principle with the source of the version information, and the project needs to be aware of its own version, e.g., to display it, then the project becomes dependent on Maven to supply the version. Maven can filter a project resource and inject the version string from the POM, or a project can access the metadata that Maven adds to its jars. But the reverse is not true; the Maven project version property must be hard-coded in the POM. It's among the few properties that are excluded from being defined by other properties.

I don't like the idea of projects being dependent on a particular build tool, but there's not much I can do about it right now. I have a couple of ideas that I may pursue later. Maybe I could have a parent POM filter the project POM and then use the filtered version to build the project. That seems pretty hackish. Or maybe I could set up another execution of maven-assembly-plugin to produce an Eclipse project archive with the version resource already filtered.

For now, I think I'll let DRY slide and duplicate the version string in the POM and source. I'll just add comments to remind me to change it in both places.

No comments:

Post a Comment