Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

52 lines (44 sloc) 1.44 KB
apply plugin: 'java-library'
apply from: 'jdks.gradle'
sourceSets {
java9 {
java {
srcDirs = ['src/main/java9']
dependencies {
// This is only necessary because in real life, we have dependencies between classes
// and what you're likely to want to do, is to provide a JDK 9 specific class, which depends on common
// classes of the main source set. In other words, you want to override some specific classes, but they
// still have dependencies onto other classes.
// We want to avoid recompiling all those classes, so we're just saying that the Java 9 specific classes
// "depend on" the main ones.
java9Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava }
compileJava {
sourceCompatibility = 8
targetCompatibility = 8
compileJava9Java {
sourceCompatibility = 9
targetCompatibility = 9
jar {
into('META-INF/versions/9') {
from sourceSets.java9.output
'Multi-Release': 'true',
'Main-Class': 'com.acme.JdkSpecific'
// You might wonder why not use the `application` plugin here?
// Well it's easy: it doesn't build the jar (because it doesn't have to,
// it can use the class directory instead), so since it's not a jar, multi-release is not seen!
// Another good reason not to use MRJars!
task run(type: JavaExec) {
dependsOn jar
classpath files(jar.archivePath)
main = 'com.acme.JdkSpecific'
You can’t perform that action at this time.