Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
Last active March 17, 2020 16:40
Show Gist options
  • Save nikolaybotev/c00d0c3267d47e5d929b6a435617c7e7 to your computer and use it in GitHub Desktop.
Save nikolaybotev/c00d0c3267d47e5d929b6a435617c7e7 to your computer and use it in GitHub Desktop.
Gradle Build with Java 9 Modules and Kotlin Support (root project)
plugins {
id 'idea'
id 'com.zyxist.chainsaw' version '0.3.1' apply false
id "org.jetbrains.kotlin.jvm" version "1.2.31" apply false
}
subprojects {
apply plugin: 'idea'
apply plugin: 'java-library'
apply plugin: 'com.zyxist.chainsaw'
}
// The idea plugin derives the JDK name as '1.9' while IDEA uses '9' as the default name for JDK 9
idea.project.jdkName = '9'
apply plugin: 'org.jetbrains.kotlin.jvm'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
// Enable Kotlin compilation to Java 8 class files wiht method parameter name metadata
compileKotlin.kotlinOptions.jvmTarget = '1.8'
compileKotlin.kotlinOptions.javaParameters = true
// As per https://stackoverflow.com/a/47669720
// See also https://discuss.kotlinlang.org/t/kotlin-support-for-java-9-module-system/2499/9
compileKotlin.destinationDir = compileJava.destinationDir
jar.duplicatesStrategy = "exclude"
// Allow cross-references between java and kotlin
sourceSets.main.kotlin.srcDirs += 'src/main/java'
@elect86
Copy link

elect86 commented Mar 17, 2020

Hi,

is this still actual?

@nikolaybotev
Copy link
Author

I am no longer a Java user and cannot speak to the current validity of this code snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment