openrewrite / openrewrite/rewrite

Enable Maven parallelism via `.mvn/maven.config` file

Open
#4,177 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What problem are you trying to solve?

The vast majority of Maven builds I've encountered are single-threaded - quite a waste of processing power in today's multi-core world. While not every multi-module Maven build will be compatible with parallelism, those that are are typically provide CLI arguments on every invocation like -T 1C or --threads 0.5C.

There is no way to provide a parallelism setting in a pom.xml file.

I recently discovered that Maven 3.3.1+ has a facility to persist default CLI arguments in a file called .mvn/maven.config (docs). (thanks @bdemers)

What precondition(s) should be checked before applying this recipe?

  1. Maven version is 3.3.1+
  2. For MVP, does .mvn/maven.config file already exist?
  3. For future releases, parameterize the parallelism factor in the recipe. Defaulting to 1C (one thread per CPU core) is a reasonable default.
  4. For future releases, parse .mvn/maven.config if exists already and add/edit -T or --threads argument.
  5. Expanding beyond that, maybe provide a general-purpose Maven CLI argument persistence recipe.

Describe the situation before applying the recipe

.mvn/maven.config does not exist

Describe the situation after applying the recipe

.mvn/maven.config is created with contents:

-T 1C

Have you considered any alternatives or workarounds?

Not really. Other than a bespoke shell script to invoke Maven, .mvn/maven.config is the only method I know of to "natively" provide CLI argument defaults.

Any additional context

If I were a consumer of this recipe, I'd want to ensure that enabling parallelism doesn't break my build and that the results before/after are the same. I'm not sure how this could be verified.

Are you interested in contributing this recipe to OpenRewrite?

Absolutely.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's Maven configuration documentation and the described before/after state: no .mvn/maven.config versus a file containing -T 1C. Identify the existing OpenRewrite recipe entry point and test conventions for creating Maven project files. Done means the recipe applies only under the stated Maven precondition and produces the requested configuration without silently expanding into the future parsing and parameterization work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.