diff --git a/build.gradle.kts b/build.gradle.kts index 5b2cc213..f0e5aa01 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,11 +39,6 @@ buildscript { } } -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - repositories { jcenter() mavenCentral() @@ -90,6 +85,37 @@ bintray { } } + +val compileJavaSource = tasks.create("compileJavaSource", JavaCompile::class) { + excludes.add("module-info.java") + val sourcedirectorySet = sourceSets.named("main").get().java + sourceCompatibility = JavaVersion.VERSION_1_8.toString() + targetCompatibility = JavaVersion.VERSION_1_8.toString() + source = sourcedirectorySet + destinationDirectory.set(sourcedirectorySet.destinationDirectory) + classpath = sourceSets.named("main").get().compileClasspath +} + +val compileModuleInfo = tasks.create("compileModuleInfo", JavaCompile::class) { + val sourcedirectorySet = sourceSets.named("main").get().java + dependsOn(compileJavaSource) + includes.add("module-info.java") + sourceCompatibility = JavaVersion.VERSION_11.toString() + targetCompatibility = JavaVersion.VERSION_11.toString() + source = sourcedirectorySet + destinationDirectory.set(sourcedirectorySet.destinationDirectory) + classpath = sourceSets.named("main").get().compileClasspath +} + +tasks.named("compileJava", JavaCompile::class.java) { + excludes.add("**/*.java") + if(JavaVersion.current().isJava9Compatible) { + dependsOn(compileModuleInfo) + } else { + dependsOn(compileJavaSource) + } +} + val sourcesJar by tasks.creating(Jar::class) { group = JavaBasePlugin.DOCUMENTATION_GROUP description = "Assembles sources JAR" diff --git a/module-info.java b/src/main/java/module-info.java similarity index 100% rename from module-info.java rename to src/main/java/module-info.java