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:
Sergey Igushkin
2018-11-08 21:07:45 +03:00
parent d23964034b
commit 635d436f02
11 changed files with 435 additions and 3 deletions
@@ -45,5 +45,7 @@ interface KotlinTarget: Named, HasAttributes {
fun mavenPublication(action: Closure<Unit>)
fun mavenPublication(action: Action<MavenPublication>)
val preset: KotlinTargetPreset<out KotlinTarget>?
override fun getName(): String = targetName
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.NamedDomainObjectCollection
interface KotlinTargetsContainer {
val targets: NamedDomainObjectCollection<KotlinTarget>
}
interface KotlinTargetsContainerWithPresets : KotlinTargetsContainer {
val presets: NamedDomainObjectCollection<KotlinTargetPreset<*>>
}