DEV Community

Clayton Walker
Clayton Walker

Posted on

Building multi-release jars (easily) with Gradle and Maven

Gradle

Use Cédric Champeau's mrjar plugin

plugins {
    id("me.champeau.mrjar") version "0.1.1"
}
Enter fullscreen mode Exit fullscreen mode
multiRelease {
    targetVersions(8, 9)
}
Enter fullscreen mode Exit fullscreen mode

See https://melix.github.io/mrjar-gradle-plugin/0.1/index.html for more details.

Maven

Use at least maven-compiler-plugin 3.7.1 which adds multiReleaseOutput

<configuration> 
    <release>9</release> 
    <compileSourceRoots> 
        <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot> 
    </compileSourceRoots> 
    <multiReleaseOutput>true</multiReleaseOutput>
</configuration>
Enter fullscreen mode Exit fullscreen mode

Then set Multi-Release: true in the maven-jar-plugin

<configuration>
    <archive>
        <manifestEntries>
            <Multi-Release>true</Multi-Release>
        </manifestEntries>
    </archive>
</configuration>
Enter fullscreen mode Exit fullscreen mode

How to add a module-info.java

todo

Top comments (0)