openrewrite / openrewrite/rewrite
Java toolchains for Maven
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What problem are you trying to solve?
Maven has the little-known ability to allow a project to specify which version of the JDK to be used for compilation and test execution, called toolchains.
The primary benefit for a Maven project is a proscriptive declaration of exactly which version of Maven should be used, removing reliance on JAVA_HOME. This can greatly reduce flakiness and errors caused by JDK fragmentation. Unfortunately, I don't believe there is a way for Maven to auto-provision (e.g. download) the JDK if a matching candidate is not located on the build host.
A secondary benefit is the decoupling the version of Java used to run Maven, vs. the JDK used to build the project. This distinction is really nice when combined with the Maven daemon, for example.
NB Gradle later implemented a similar feature.
What precondition(s) should be checked before applying this recipe?
- Maven version is 3.3.1+
- If any of the listed plugins here are present, do they meet the required minimum versions?
- For MVP, does
toolchains.xmlfile already exist?
Describe the situation before applying the recipe
Root pom.xml
maven-toolchains-plugin plugin not present
Describe the situation after applying the recipe
Something similar to below is added to root pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<!-- Configure your toolchain requirements here -->
<toolchain-type>
<param>expected value</param>
...
</toolchain-type>
...
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Have you considered any alternatives or workarounds?
Can the toolchains.xml file be centrally located, such as in ${user.home}/.m2/? A large organization might prefer this to adding the file to every project.
Any additional context
Should the recipe use the Foojay Disco API (docs) to also download the JDK?
If yes, should this step happen first, then allow the maven-toolchains-plugin to discover and auto-generate its toolchain.xml file? (notes on discovery and generation)
Are you interested in contributing this recipe to OpenRewrite?
Yes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the root pom.xml example and the Maven toolchains prerequisites, then review the toolchains.xml discovery and generation links mentioned in the issue. Define the MVP scope and verify that the resulting root pom.xml contains the requested maven-toolchains-plugin configuration while addressing the unresolved JDK provisioning questions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100