简体   繁体   中英

Gradle Maven Publish Plugin with Multiple JDK

I have a Java library project that I wanted to publish using Maven Publish Plugin. The challenge that I have is I wanted to publish it to the same local nexus repository but compiled using multiple JDK versions. Like I wanted to compile same source using JDK 1.8 and JDK 11. The reason I am doing that is because, I have multiple consumers to my project and wanted to make sure I am able to provide the correct artifact.

I got this Idea from seeing the Microsoft's MSSQL Server drivers. They have same version of the drivers published specifically for individual JDKs.

Thanks in advance!

The use case you described is precisely the use case for which Multi-Release JAR Files were invented.

The mrJar Gradle plugin is a plugin that was invented precisely for that very MRJAR use case.

In fact, the mrJar plugin uses itself to create the very JAR that it is published to the plugin portal in. It dog foods itself in its build process to create a Modular Multi-Release JAR artifact that gets distributed from the plugin repository.

For example: Only versions of Gradle 6.0 or higher support Java 13. The JAR file of the mrJar plugin that is published on Gradle's plugin portal has the smarts to only provide Java 13 support only when it is applied in a project running in Java 13. When the plugin is running in Java 8, 9, 10, 11, 12 the Java 13 features are non-existent.

I'm pretty sure using the mrJar plugin is the solution to the use case your question describes. These Usage instructions will step you through what you need to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM