https://github.com/linux-china/toolchains-maven-plugin
Toolchains Maven Plugin with JDK auto download
https://github.com/linux-china/toolchains-maven-plugin
maven-plugin toolchains
Last synced: 9 months ago
JSON representation
Toolchains Maven Plugin with JDK auto download
- Host: GitHub
- URL: https://github.com/linux-china/toolchains-maven-plugin
- Owner: linux-china
- License: apache-2.0
- Created: 2021-10-26T21:38:50.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T05:10:46.000Z (over 2 years ago)
- Last Synced: 2025-04-02T02:51:14.896Z (10 months ago)
- Topics: maven-plugin, toolchains
- Language: Java
- Homepage:
- Size: 354 KB
- Stars: 41
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Toolchains Maven Plugin
=========================
Extend maven-toolchains-plugin to add JDK auto download and toolchains.xml management.
# Features
* JDK auto download by Foojay API support, and install directory is `~/.m2/jdks`
* Add new toolchain into toolchains.xml dynamically
* SDKMAN integration: add JDK to toolchains.xml from [SDKMAN](https://sdkman.io/) if SDKMAN detected
* JBang integration: add/auto-install JDK to toolchains.xml from [JBang](https://www.jbang.dev/) if jbang detected
# Requirements
* Maven 3.5+
* JDK 1.7+
# How to use?
Add following plugin configuration to your pom.xml:
```xml
org.mvnsearch
toolchains-maven-plugin
4.5.0
toolchain
17
```
And you can try it quickly:
```
$ git clone https://github.com/linux-china/java17-demo.git
$ cd java17-demo
$ mvn compile
```
# GraalVM support
* vendor should be `graalvm_ce17` or `graalvm_ce11`
* version is GraalVM version(not Java version), such as `22.3` or `22.3.0`
* GraalVM native-image component will be installed automatically
```xml
org.mvnsearch
toolchains-maven-plugin
4.5.0
toolchain
22.3
graalvm_ce17
```
# How to get a list of all supported distributions and JDK versions?
Please visit https://api.foojay.io/disco/v3.0/distributions to get all information.
* jdk vendor is the value of `api_parameter`
* jdk version value could be any value in `versions` array
Or you can use [Maven toolchains CLI](https://github.com/linux-china/maven-toolchains-cli) to get all supported JDKs information.

# How to skip toolchains maven plugin on CI/CD platform?
```
$ mvn -Dtoolchain.skip -DskipTests package
```
# Different JDK for main/test code
Maven has support for using different source and target java versions for your project's main code and tests.
You can add `testJdk` toolchain in `toolchains-maven-plugin` to specify the JDK for test code as below:
```xml
org.apache.maven.plugins
maven-compiler-plugin
3.11.0
default-testCompile
test-compile
testCompile
18
8
8
true
18
18
18
--enable-preview
org.mvnsearch
toolchains-maven-plugin
4.5.0
toolchain
8
18
```
# References
* Apache Maven Toolchains Plugin: https://maven.apache.org/plugins/maven-toolchains-plugin/
* Maven toolchains CLI: https://github.com/linux-china/maven-toolchains-cli
* Disco CLI: a command line interface for the foojay.io Disco API - https://github.com/HanSolo/discocli
* foojay DiscoAPI: https://api.foojay.io/swagger-ui/
* Gradle Toolchains for JVM:https://docs.gradle.org/current/userguide/toolchains.html
sdkman support: sdk install java 17.0.7-graalce