Gradle: support moduleName option in KotlinJvmOptions

#KT-42058 Fixed
This commit is contained in:
Alexander Udalov
2020-09-20 18:35:05 +02:00
committed by Alexander Udalov
parent 0edbdaf0c7
commit cb5c317f91
6 changed files with 61 additions and 0 deletions
@@ -63,6 +63,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
)
var scriptTemplates: Array<String>? by FreezableVar(null)
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
var moduleName: String? by NullableStringFreezableVar(null)
@@ -73,6 +73,16 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
}
}
@Test
fun testModuleName() {
Project("moduleName").build("build") {
assertSuccessful()
assertFileExists("build/classes/kotlin/main/META-INF/FLAG.kotlin_module")
assertNoSuchFile("build/classes/kotlin/main/META-INF/moduleName.kotlin_module")
assertNotContains("Argument -module-name is passed multiple times")
}
}
@Test
fun testCustomJdk() {
Project("customJdk").build("build") {
@@ -0,0 +1,32 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
sourceSets {
main {
kotlin {
srcDir 'src'
}
}
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
compileKotlin {
kotlinOptions.moduleName = "FLAG"
}
@@ -0,0 +1,3 @@
interface A {
fun foo(): Int = 1
}
@@ -29,6 +29,12 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
*/
var jvmTarget: kotlin.String
/**
* Name of the generated .kotlin_module file
* Default value: null
*/
var moduleName: kotlin.String?
/**
* Don't automatically include the Java runtime into the classpath
* Default value: false
@@ -67,6 +67,13 @@ internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.K
jvmTargetField = value
}
private var moduleNameField: kotlin.String?? = null
override var moduleName: kotlin.String?
get() = moduleNameField ?: null
set(value) {
moduleNameField = value
}
private var noJdkField: kotlin.Boolean? = null
override var noJdk: kotlin.Boolean
get() = noJdkField ?: false
@@ -105,6 +112,7 @@ internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.K
javaParametersField?.let { args.javaParameters = it }
jdkHomeField?.let { args.jdkHome = it }
jvmTargetField?.let { args.jvmTarget = it }
moduleNameField?.let { args.moduleName = it }
noJdkField?.let { args.noJdk = it }
noReflectField?.let { args.noReflect = it }
noStdlibField?.let { args.noStdlib = it }
@@ -122,6 +130,7 @@ internal fun org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.fi
javaParameters = false
jdkHome = null
jvmTarget = "1.6"
moduleName = null
noJdk = false
noReflect = true
noStdlib = true