Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build a modular jar (still compatible with java 8) if compiled with jdk 9 or greater #504

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ buildscript {
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
jcenter()
mavenCentral()
Expand Down Expand Up @@ -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"
Expand Down
File renamed without changes.