Skip to content
Benjamin Wootton.Better Software
Software

7 Habits Of Highly Effective Maven Users

Undated

By Benjamin Wootton

2 min read

Maven is easy to use badly. A large build file, a tangle of profiles and a dependency list nobody reviews can turn a helpful tool into a source of friction. The teams that get the most from it tend to share a small set of habits.

1. Let the lifecycle do the work

Maven already knows how to compile, test, package and install. Use the standard phases rather than inventing a new sequence of scripts. A new developer should be able to run one command and get a build that behaves like everyone else's.

2. Keep the build file small

The less the build file says, the more it means. Put shared configuration in a parent, use conventions where they exist and remove settings that only exist because someone once worked around a problem that has since gone away.

3. Treat dependencies as a budget

Every dependency is code you did not write and now have to keep current. Add them deliberately, review them regularly and remove the ones that are no longer used. A lean dependency tree is easier to secure and easier to upgrade.

4. Manage versions in one place

Properties or a dependency management section keep versions consistent across modules. When a library is upgraded, the change should happen once, not in every module that happens to use it.

5. Keep profiles rare

Profiles are useful for genuinely different environments, but they multiply quickly. If a build only works with a particular combination of profiles, the team has created a puzzle rather than a build. Prefer a small number of clear profiles with obvious names.

6. Make tests part of every build

The test phase should run by default, and a failing test should fail the build. A build that can be made green by skipping tests is not giving the team a signal. Keep the fast tests in the default lifecycle and move the slow ones into a clearly named integration phase.

7. Publish and document the build

Use the site and reporting features to publish the build information the team needs: test results, coverage and dependency reports. Documentation that is generated from the build is more likely to stay current than a page someone remembers to update.

None of these habits is dramatic on its own. Together they turn Maven from a tool the team tolerates into a tool the team relies on. For the longer version, read how Maven enforces good habits, then CI tools for the next step in automation.

Reference shelf

Sources and further reading for this note.