Provide preset-like factory functions for creating targets in new MPP
* Pull the `targets` and `presets` properties of the `kotlin` extension
up to an interface in `kotlin-gradle-plugin-api`
* Generate the code: we need type-safe statically-typed functions for
different target type, which seems to be only possible to achieve by
providing a function per preset.
* Place these functions in the top-level `kotlin` Gradle extension,
rather than extension functions for `kotlin.targets`:
- `kotlin.jvm { ... }` will work, while `kotlin.targets.jvm { ... }`
won't, the extension function needs to be somehow brought into scope
- reducing the nesting level by one seems to be a good move here
Issue #KT-26389 Fixed
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(gradleApi())
|
||||
compile(project(":kotlin-gradle-plugin-api"))
|
||||
compile(project(":kotlin-native:kotlin-native-utils"))
|
||||
}
|
||||
|
||||
val generateMppTargetContainerWithPresets by generator(
|
||||
"org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt",
|
||||
sourceSets["main"]
|
||||
)
|
||||
|
||||
generateMppTargetContainerWithPresets.run {
|
||||
systemProperty(
|
||||
"org.jetbrains.kotlin.generators.gradle.dsl.outputSourceRoot",
|
||||
project(":kotlin-gradle-plugin").projectDir.resolve("src/main/kotlin").absolutePath
|
||||
)
|
||||
}
|
||||
|
||||
// Workaround: 'java -jar' refuses to read the original dotted filename on Windows, 'Unable to access jarFile org.jetbrains.kotlin....jar'
|
||||
tasks.named<Jar>(generateMppTargetContainerWithPresets.name + "WriteClassPath").configure {
|
||||
archiveName = generateMppTargetContainerWithPresets.name
|
||||
}
|
||||
Reference in New Issue
Block a user