Precise platform importing changes ported from new repository

This commit is contained in:
Yaroslav Chernyshev
2021-03-11 22:30:38 +03:00
parent 960a7dca45
commit d053ee33a8
16 changed files with 409 additions and 87 deletions
@@ -41,7 +41,7 @@ class KotlinSourceSetInfo @PropertyMapping("kotlinModule") constructor(val kotli
@Deprecated("Returns only single TargetPlatform", ReplaceWith("actualPlatforms.actualPlatforms"), DeprecationLevel.ERROR)
val platform: KotlinPlatform
get() = actualPlatforms.getSinglePlatform()
get() = actualPlatforms.platforms.singleOrNull() ?: KotlinPlatform.COMMON
@Transient
var defaultCompilerArguments: CommonCompilerArguments? = null
@@ -0,0 +1,9 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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
@RequiresOptIn(level = RequiresOptIn.Level.WARNING, message = "This API might change in the future")
annotation class ExperimentalGradleToolingApi
@@ -21,5 +21,5 @@ interface KotlinSourceSetImportingDiagnostic : KotlinImportingDiagnostic {
data class OrphanSourceSetsImportingDiagnostic(override val kotlinSourceSet: KotlinSourceSet) : KotlinSourceSetImportingDiagnostic {
override fun deepCopy(cache: MutableMap<Any, Any>): OrphanSourceSetsImportingDiagnostic =
(cache[kotlinSourceSet] as? KotlinSourceSet)?.let { OrphanSourceSetsImportingDiagnostic(it) }
?: OrphanSourceSetsImportingDiagnostic(KotlinSourceSetImpl(kotlinSourceSet, cache).apply { cache[kotlinSourceSet] = this })
?: OrphanSourceSetsImportingDiagnostic(KotlinSourceSetImpl(kotlinSourceSet).apply { cache[kotlinSourceSet] = this })
}
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")
package org.jetbrains.kotlin.gradle
import org.jetbrains.plugins.gradle.model.ExternalDependency
@@ -53,12 +55,43 @@ interface KotlinSourceSet : KotlinModule {
val languageSettings: KotlinLanguageSettings
val sourceDirs: Set<File>
val resourceDirs: Set<File>
val dependsOnSourceSets: Set<String>
val actualPlatforms: KotlinPlatformContainer
@Deprecated("Returns single target platform", ReplaceWith("actualPlatforms.actualPlatforms"), DeprecationLevel.ERROR)
/**
* All source sets that this source set explicitly declared a 'dependsOn' relation to
*/
val declaredDependsOnSourceSets: Set<String>
/**
* The whole transitive closure of source sets this source set depends on.
* ([declaredDependsOnSourceSets] and their dependencies recursively)
*/
@Suppress("DEPRECATION")
@Deprecated(
"This property might be misleading. " +
"Replace with 'KotlinSourceSetContainer.resolveAllDependsOnSourceSets' to make intention of " +
"receiving the full transitive closure explicit",
level = DeprecationLevel.ERROR
)
val dependsOnSourceSets: Set<String>
get() = allDependsOnSourceSets
/**
* The whole transitive closure of source sets this source set depends on.
* ([declaredDependsOnSourceSets] and their dependencies recursively)
*/
@Deprecated(
"This set of source sets might be inconsistent with any KotlinSourceSetContainer different to the one used to build this instance" +
"Replace with 'KotlinSourceSetContainer.resolveAllDependsOnSourceSets' to get consistent resolution",
level = DeprecationLevel.WARNING
)
val allDependsOnSourceSets: Set<String>
@Deprecated("Returns single target platform. Use actualPlatforms instead", level = DeprecationLevel.ERROR)
val platform: KotlinPlatform
get() = actualPlatforms.getSinglePlatform()
get() = actualPlatforms.platforms.singleOrNull() ?: KotlinPlatform.COMMON
companion object {
@@ -98,6 +131,11 @@ interface KotlinNativeCompilationExtensions : Serializable {
}
interface KotlinCompilation : KotlinModule {
@Deprecated("Use allSourceSets or declaredSourceSets instead")
val sourceSets: Collection<KotlinSourceSet>
get() = declaredSourceSets
/**
* All source sets participated in this compilation, including those available
* via dependsOn.
@@ -105,14 +143,14 @@ interface KotlinCompilation : KotlinModule {
val allSourceSets: Collection<KotlinSourceSet>
/**
* Only default source sets of this compilation, i.e. those which are included
* Only directly declared source sets of this compilation, i.e. those which are included
* into compilations directly.
*
* Usually, those are automatically created source sets for automatically created
* compilations (like jvmMain for JVM compilations) or manually included source sets
* (like 'jvm().compilations["main"].source(mySourceSet)' )
*/
val defaultSourceSets: Collection<KotlinSourceSet>
val declaredSourceSets: Collection<KotlinSourceSet>
val output: KotlinCompilationOutput
val arguments: KotlinCompilationArguments
@@ -140,15 +178,50 @@ enum class KotlinPlatform(val id: String) {
}
}
interface KotlinPlatformContainer : Serializable {
interface KotlinPlatformContainer : Serializable, Iterable<KotlinPlatform> {
/**
* Distinct collection of Platforms.
* Keeping 'Collection' as type for binary compatibility
*/
val platforms: Collection<KotlinPlatform>
val arePlatformsInitialized: Boolean
@Deprecated(
"Ambiguous semantics of 'supports' for COMMON or (ANDROID/JVM) platforms. Use 'platforms' directly to express clear intention",
level = DeprecationLevel.ERROR
)
fun supports(simplePlatform: KotlinPlatform): Boolean
fun addSimplePlatforms(platforms: Collection<KotlinPlatform>)
@Deprecated(
"Unclear semantics: Use 'platforms' directly to express intention",
level = DeprecationLevel.ERROR
)
fun getSinglePlatform() = platforms.singleOrNull() ?: KotlinPlatform.COMMON
@Deprecated(
"Unclear semantics: Use 'pushPlatform' instead",
ReplaceWith("pushPlatform"),
level = DeprecationLevel.ERROR
)
fun addSimplePlatforms(platforms: Collection<KotlinPlatform>) = pushPlatforms(platforms)
/**
* Adds the given [platforms] to this container.
* Note: If any of the pushed [platforms] is common, then this container will drop all non-common platforms and subsequent invocations
* to this function will have no further effect.
*/
fun pushPlatforms(platforms: Iterable<KotlinPlatform>)
/**
* @see pushPlatforms
*/
fun pushPlatforms(vararg platform: KotlinPlatform) {
pushPlatforms(platform.toList())
}
override fun iterator(): Iterator<KotlinPlatform> {
return platforms.toSet().iterator()
}
}
@@ -190,14 +263,19 @@ interface ExtraFeatures : Serializable {
val isNativeDependencyPropagationEnabled: Boolean
}
interface KotlinMPPGradleModel : Serializable {
interface KotlinMPPGradleModel : KotlinSourceSetContainer, Serializable {
val dependencyMap: Map<KotlinDependencyId, KotlinDependency>
val sourceSets: Map<String, KotlinSourceSet>
val targets: Collection<KotlinTarget>
val extraFeatures: ExtraFeatures
val kotlinNativeHome: String
val kotlinImportingDiagnostics: KotlinImportingDiagnosticsContainer
@Deprecated("Use 'sourceSetsByName' instead", ReplaceWith("sourceSetsByName"), DeprecationLevel.ERROR)
val sourceSets: Map<String, KotlinSourceSet>
get() = sourceSetsByName
override val sourceSetsByName: Map<String, KotlinSourceSet>
companion object {
const val NO_KOTLIN_NATIVE_HOME = ""
}
@@ -45,46 +45,46 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
}
override fun buildAll(modelName: String, project: Project): Any? {
val projectTargets = project.getTargets() ?: return null
val dependencyResolver = DependencyResolverImpl(
project,
false,
false,
true,
SourceSetCachedFinder(project)
)
val dependencyMapper = KotlinDependencyMapper()
val importingContext = MultiplatformModelImportingContextImpl(project)
try {
val projectTargets = project.getTargets() ?: return null
val dependencyResolver = DependencyResolverImpl(project, false, true, SourceSetCachedFinder(project))
val dependencyMapper = KotlinDependencyMapper()
val importingContext = MultiplatformModelImportingContextImpl(project)
importingContext.initializeSourceSets(buildSourceSets(importingContext, dependencyResolver, dependencyMapper) ?: return null)
importingContext.initializeSourceSets(buildSourceSets(importingContext, dependencyResolver, dependencyMapper) ?: return null)
val targets = buildTargets(importingContext, projectTargets, dependencyResolver, dependencyMapper)
importingContext.initializeTargets(targets)
importingContext.initializeCompilations(targets.flatMap { it.compilations })
val targets = buildTargets(importingContext, projectTargets, dependencyResolver, dependencyMapper)
importingContext.initializeTargets(targets)
importingContext.initializeCompilations(targets.flatMap { it.compilations })
computeSourceSetsDeferredInfo(importingContext)
computeSourceSetsDeferredInfo(importingContext)
val coroutinesState = getCoroutinesState(project)
val kotlinNativeHome = KotlinNativeHomeEvaluator.getKotlinNativeHome(project) ?: NO_KOTLIN_NATIVE_HOME
return KotlinMPPGradleModelImpl(
filterOrphanSourceSets(importingContext),
importingContext.targets,
ExtraFeaturesImpl(
coroutinesState,
importingContext.getProperty(IS_HMPP_ENABLED),
importingContext.getProperty(ENABLE_NATIVE_DEPENDENCY_PROPAGATION)
),
kotlinNativeHome,
dependencyMapper.toDependencyMap()
).apply {
kotlinImportingDiagnostics += collectDiagnostics(importingContext)
val coroutinesState = getCoroutinesState(project)
val kotlinNativeHome = KotlinNativeHomeEvaluator.getKotlinNativeHome(project) ?: NO_KOTLIN_NATIVE_HOME
val model = KotlinMPPGradleModelImpl(
sourceSetsByName = filterOrphanSourceSets(importingContext),
targets = importingContext.targets,
extraFeatures = ExtraFeaturesImpl(
coroutinesState = coroutinesState,
isHMPPEnabled = importingContext.getProperty(IS_HMPP_ENABLED),
isNativeDependencyPropagationEnabled = importingContext.getProperty(ENABLE_NATIVE_DEPENDENCY_PROPAGATION)
),
kotlinNativeHome = kotlinNativeHome,
dependencyMap = dependencyMapper.toDependencyMap()
).apply {
kotlinImportingDiagnostics += collectDiagnostics(importingContext)
}
return model
} catch (throwable: Throwable) {
project.logger.error("Failed building KotlinMPPGradleModel", throwable)
throw throwable
}
}
private fun filterOrphanSourceSets(
importingContext: MultiplatformModelImportingContext
): Map<String, KotlinSourceSetImpl> {
if (importingContext.getProperty(IMPORT_ORPHAN_SOURCE_SETS)) return importingContext.sourceSetsByNames
if (importingContext.getProperty(IMPORT_ORPHAN_SOURCE_SETS)) return importingContext.sourceSetsByName
val (orphanSourceSets, nonOrphanSourceSets) = importingContext.sourceSets.partition { importingContext.isOrphanSourceSet(it) }
@@ -118,17 +118,16 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
val allSourceSetsProtosByNames = sourceSets.mapNotNull {
buildSourceSet(it, dependencyResolver, importingContext.project, dependencyMapper, androidDeps)
}.associateBy { it.name }
val dependsOnCache = HashMap<String, Set<String>>()
// Some performance optimisation: do not build metadata dependencies if source set is not common
return if (importingContext.getProperty(BUILD_METADATA_DEPENDENCIES)) {
allSourceSetsProtosByNames.mapValues { (_, proto) ->
proto.buildKotlinSourceSetImpl(true, allSourceSetsProtosByNames, dependsOnCache)
proto.buildKotlinSourceSetImpl(true, allSourceSetsProtosByNames)
}
} else {
val unactualizedSourceSets = allSourceSetsProtosByNames.values.flatMap { it.dependsOnSourceSets }.distinct()
allSourceSetsProtosByNames.mapValues { (name, proto) ->
proto.buildKotlinSourceSetImpl(unactualizedSourceSets.contains(name), allSourceSetsProtosByNames, dependsOnCache)
proto.buildKotlinSourceSetImpl(unactualizedSourceSets.contains(name), allSourceSetsProtosByNames)
}
}
}
@@ -306,8 +305,9 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
): KotlinTarget? {
val targetClass = gradleTarget.javaClass
val metadataTargetClass = targetClass.classLoader.loadClass("org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget")
if (metadataTargetClass.isInstance(gradleTarget)) return null
/* Loading class safely to still support Kotlin Gradle Plugin 1.3.30 */
val metadataTargetClass = targetClass.classLoader.loadClassOrNull("org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget")
if (metadataTargetClass?.isInstance(gradleTarget) == true) return null
val getPlatformType = targetClass.getMethodOrNull("getPlatformType") ?: return null
val getDisambiguationClassifier = targetClass.getMethodOrNull("getDisambiguationClassifier") ?: return null
@@ -494,23 +494,20 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
}
val nativeExtensions = konanTarget?.let(::KotlinNativeCompilationExtensionsImpl)
val allSourceSets = if (platform != KotlinPlatform.ANDROID) {
kotlinSourceSets
} else {
kotlinSourceSets.flatMap { it.dependsOnSourceSets }.mapNotNull { importingContext.sourceSetByName(it) }
.union(kotlinSourceSets)
}
val allSourceSets = kotlinSourceSets
.flatMap { sourceSet -> importingContext.resolveAllDependsOnSourceSets(sourceSet) }
.union(kotlinSourceSets)
return KotlinCompilationImpl(
gradleCompilation.name,
allSourceSets,
kotlinSourceSets,
dependencies.map { dependencyMapper.getId(it) }.distinct().toTypedArray(),
output,
arguments,
dependencyClasspath.toTypedArray(),
kotlinTaskProperties,
nativeExtensions
name = gradleCompilation.name,
allSourceSets = allSourceSets,
declaredSourceSets = if (platform == KotlinPlatform.ANDROID) allSourceSets else kotlinSourceSets,
dependencies = dependencies.map { dependencyMapper.getId(it) }.distinct().toTypedArray(),
output = output,
arguments = arguments,
dependencyClasspath = dependencyClasspath.toTypedArray(),
kotlinTaskProperties = kotlinTaskProperties,
nativeExtensions = nativeExtensions
)
}
@@ -737,24 +734,24 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
// Explicitly set platform of orphan source-sets to only used platforms, not all supported platforms
// Otherwise, the tooling might be upset after trying to provide some support for a target which actually
// doesn't exist in this project (e.g. after trying to draw gutters, while test tasks do not exist)
sourceSet.actualPlatforms.addSimplePlatforms(projectPlatforms)
sourceSet.actualPlatforms.pushPlatforms(projectPlatforms)
return
}
if (shouldCoerceToCommon(sourceSet)) {
sourceSet.actualPlatforms.addSimplePlatforms(listOf(KotlinPlatform.COMMON))
sourceSet.actualPlatforms.pushPlatforms(KotlinPlatform.COMMON)
return
}
if (!getProperty(IS_HMPP_ENABLED) && !isDefaultSourceSet(sourceSet)) {
if (!getProperty(IS_HMPP_ENABLED) && !isDeclaredSourceSet(sourceSet)) {
// intermediate source sets should be common if HMPP is disabled
sourceSet.actualPlatforms.addSimplePlatforms(listOf(KotlinPlatform.COMMON))
sourceSet.actualPlatforms.pushPlatforms(KotlinPlatform.COMMON)
return
}
compilationsBySourceSet(sourceSet)?.let { compilations ->
val platforms = compilations.map { it.platform }
sourceSet.actualPlatforms.addSimplePlatforms(platforms)
sourceSet.actualPlatforms.pushPlatforms(platforms)
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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
interface KotlinSourceSetContainer {
val sourceSetsByName: Map<String, KotlinSourceSet>
}
val KotlinSourceSetContainer.sourceSets: List<KotlinSourceSet> get() = sourceSetsByName.values.toList()
fun KotlinSourceSetContainer.resolveDeclaredDependsOnSourceSets(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
return sourceSet.declaredDependsOnSourceSets.mapNotNull { name -> sourceSetsByName[name] }.toSet()
}
fun KotlinSourceSetContainer.resolveAllDependsOnSourceSets(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
/* Fast path */
if (sourceSet.declaredDependsOnSourceSets.isEmpty()) return emptySet()
/* Aggregating set containing all currently resolved source sets */
val resolvedSourceSets = mutableSetOf<KotlinSourceSet>()
/* Queue of source set names that shall be resolved */
val declaredDependsOnSourceSetsQueue = ArrayDeque<String>()
declaredDependsOnSourceSetsQueue.addAll(sourceSet.declaredDependsOnSourceSets)
while (declaredDependsOnSourceSetsQueue.isNotEmpty()) {
val sourceSetName = declaredDependsOnSourceSetsQueue.removeFirst()
val resolvedSourceSet = sourceSetsByName[sourceSetName]
if (resolvedSourceSet != null) {
if (resolvedSourceSets.add(resolvedSourceSet)) {
declaredDependsOnSourceSetsQueue.addAll(resolvedSourceSet.declaredDependsOnSourceSets)
}
}
}
return resolvedSourceSets
}
fun KotlinSourceSetContainer.isDependsOn(from: KotlinSourceSet, to: KotlinSourceSet): Boolean {
return to in resolveAllDependsOnSourceSets(from)
}
fun KotlinSourceSet.isDependsOn(model: KotlinSourceSetContainer, sourceSet: KotlinSourceSet): Boolean {
return model.isDependsOn(from = this, to = sourceSet)
}
@@ -15,7 +15,7 @@ internal object OrphanSourceSetImportingChecker : MultiplatformModelImportingChe
reportTo: KotlinImportingDiagnosticsContainer,
context: MultiplatformModelImportingContext
) {
model.sourceSets.values.filter { context.isOrphanSourceSet(it) }
model.sourceSetsByName.values.filter { context.isOrphanSourceSet(it) }
.mapTo(reportTo) { OrphanSourceSetsImportingDiagnostic(it) }
}
}
@@ -8,9 +8,8 @@ package org.jetbrains.kotlin.gradle
import org.gradle.api.Project
import org.gradle.api.logging.Logging
private val logger = Logging.getLogger(KotlinMPPGradleModelBuilder::class.java)
internal interface MultiplatformModelImportingContext {
internal interface MultiplatformModelImportingContext: KotlinSourceSetContainer {
val project: Project
val targets: Collection<KotlinTarget>
@@ -20,8 +19,8 @@ internal interface MultiplatformModelImportingContext {
* All source sets in a project, including those that are created but not included into any compilations
* (so-called "orphan" source sets). Use [isOrphanSourceSet] to get only compiled source sets
*/
val sourceSets: Collection<KotlinSourceSetImpl>
val sourceSetsByNames: Map<String, KotlinSourceSetImpl>
val sourceSets: Collection<KotlinSourceSetImpl> get() = sourceSetsByName.values
override val sourceSetsByName: Map<String, KotlinSourceSetImpl>
/**
* Platforms, which are actually used in this project (i.e. platforms, for which targets has been created)
@@ -41,12 +40,12 @@ internal interface MultiplatformModelImportingContext {
fun isOrphanSourceSet(sourceSet: KotlinSourceSet): Boolean = compilationsBySourceSet(sourceSet) == null
/**
* "Default" source-set is a source-set which is included into compilation directly, rather
* "Declared" source-set is a source-set which is included into compilation directly, rather
* through closure over dependsOn-relation.
*
* See also KDoc for [KotlinCompilation.defaultSourceSets]
* See also KDoc for [KotlinCompilation.declaredSourceSets]
*/
fun isDefaultSourceSet(sourceSet: KotlinSourceSet): Boolean
fun isDeclaredSourceSet(sourceSet: KotlinSourceSet): Boolean
}
internal fun MultiplatformModelImportingContext.getProperty(property: GradleImportProperties): Boolean = project.getProperty(property)
@@ -75,16 +74,14 @@ internal enum class GradleImportProperties(val id: String, val defaultValue: Boo
internal class MultiplatformModelImportingContextImpl(override val project: Project) : MultiplatformModelImportingContext {
/** see [initializeSourceSets] */
override lateinit var sourceSetsByNames: Map<String, KotlinSourceSetImpl>
override lateinit var sourceSetsByName: Map<String, KotlinSourceSetImpl>
private set
override val sourceSets: Collection<KotlinSourceSetImpl>
get() = sourceSetsByNames.values
/** see [initializeCompilations] */
override lateinit var compilations: Collection<KotlinCompilation>
private set
private lateinit var sourceSetToParticipatedCompilations: Map<KotlinSourceSet, Set<KotlinCompilation>>
private lateinit var allDefaultSourceSets: Set<KotlinSourceSet>
private lateinit var allDeclaredSourceSets: Set<KotlinSourceSet>
/** see [initializeTargets] */
@@ -95,12 +92,13 @@ internal class MultiplatformModelImportingContextImpl(override val project: Proj
private set
internal fun initializeSourceSets(sourceSetsByNames: Map<String, KotlinSourceSetImpl>) {
require(!this::sourceSetsByNames.isInitialized) {
"Attempt to re-initialize source sets for $this. Previous value: ${this.sourceSetsByNames}"
require(!this::sourceSetsByName.isInitialized) {
"Attempt to re-initialize source sets for $this. Previous value: ${this.sourceSetsByName}"
}
this.sourceSetsByNames = sourceSetsByNames
this.sourceSetsByName = sourceSetsByNames
}
@OptIn(ExperimentalGradleToolingApi::class)
internal fun initializeCompilations(compilations: Collection<KotlinCompilation>) {
require(!this::compilations.isInitialized) { "Attempt to re-initialize compilations for $this. Previous value: ${this.compilations}" }
this.compilations = compilations
@@ -111,7 +109,7 @@ internal class MultiplatformModelImportingContextImpl(override val project: Proj
for (compilation in target.compilations) {
for (sourceSet in compilation.allSourceSets) {
sourceSetToCompilations.getOrPut(sourceSet) { LinkedHashSet() } += compilation
sourceSet.dependsOnSourceSets.mapNotNull { sourceSetByName(it) }.forEach {
resolveAllDependsOnSourceSets(sourceSet).forEach {
sourceSetToCompilations.getOrPut(it) { LinkedHashSet() } += compilation
}
}
@@ -120,7 +118,7 @@ internal class MultiplatformModelImportingContextImpl(override val project: Proj
this.sourceSetToParticipatedCompilations = sourceSetToCompilations
this.allDefaultSourceSets = compilations.flatMapTo(mutableSetOf()) { it.defaultSourceSets }
this.allDeclaredSourceSets = compilations.flatMapTo(mutableSetOf()) { it.declaredSourceSets }
}
internal fun initializeTargets(targets: Collection<KotlinTarget>) {
@@ -132,10 +130,10 @@ internal class MultiplatformModelImportingContextImpl(override val project: Proj
// overload for small optimization
override fun isOrphanSourceSet(sourceSet: KotlinSourceSet): Boolean = sourceSet !in sourceSetToParticipatedCompilations.keys
override fun isDefaultSourceSet(sourceSet: KotlinSourceSet): Boolean = sourceSet in allDefaultSourceSets
override fun isDeclaredSourceSet(sourceSet: KotlinSourceSet): Boolean = sourceSet in allDeclaredSourceSets
override fun compilationsBySourceSet(sourceSet: KotlinSourceSet): Collection<KotlinCompilation>? =
sourceSetToParticipatedCompilations[sourceSet]
override fun sourceSetByName(name: String): KotlinSourceSet? = sourceSetsByNames[name]
override fun sourceSetByName(name: String): KotlinSourceSet? = sourceSetsByName[name]
}
+11 -1
View File
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.gradle
import org.gradle.api.Named
fun Class<*>.getMethodOrNull(name: String, vararg parameterTypes: Class<*>) =
try {
getMethod(name, *parameterTypes)
@@ -19,5 +21,13 @@ fun Class<*>.getDeclaredMethodOrNull(name: String, vararg parameterTypes: Class<
null
}
fun ClassLoader.loadClassOrNull(name: String): Class<*>? {
return try {
loadClass(name)
} catch (e: Exception) {
return null
}
}
fun compilationFullName(simpleName: String, classifier: String?) =
if (classifier != null) classifier + simpleName.capitalize() else simpleName
if (classifier != null) classifier + simpleName.capitalize() else simpleName
@@ -0,0 +1,71 @@
/**
* commonMain----
* / \
* jvmAndLinuxMain \
* / \ \
* jvm linuxX64 macosX64
*
* (the tests structure is the same)
*/
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform").version("{{kotlin_plugin_version}}")
}
group = "project"
version = "1.0"
kotlin {
jvm()
linuxX64()
macosX64()
sourceSets {
val commonMain by getting {
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmAndLinuxMain by creating {
dependsOn(commonMain)
}
val jvmAndLinuxTest by creating {
dependsOn(commonTest)
}
val jvmMain by getting {
dependsOn(jvmAndLinuxMain)
}
val jvmTest by getting {
dependsOn(jvmAndLinuxTest)
dependencies {
implementation(kotlin("test-junit"))
}
}
val linuxX64Main by getting {
dependsOn(jvmAndLinuxMain)
}
val linuxX64Test by getting {
dependsOn(jvmAndLinuxTest)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,9 @@
pluginManagement {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
rootProject.name = "my-app"
enableFeaturePreview("GRADLE_METADATA")
@@ -0,0 +1,71 @@
/**
* commonMain----
* / \
* jvmAndLinuxMain \
* / \ \
* jvm linuxX64 macosX64
*
* (the tests structure is the same)
*/
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform").version("{{kotlin_plugin_version}}")
}
group = "project"
version = "1.0"
kotlin {
jvm()
linuxX64()
macosX64()
sourceSets {
val commonMain by getting {
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmAndLinuxMain by creating {
dependsOn(commonMain)
}
val jvmAndLinuxTest by creating {
dependsOn(commonTest)
}
val jvmMain by getting {
dependsOn(jvmAndLinuxMain)
}
val jvmTest by getting {
dependsOn(jvmAndLinuxTest)
dependencies {
implementation(kotlin("test-junit"))
}
}
val linuxX64Main by getting {
dependsOn(jvmAndLinuxMain)
}
val linuxX64Test by getting {
dependsOn(jvmAndLinuxTest)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,11 @@
pluginManagement {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
rootProject.name = "my-app"
enableFeaturePreview("GRADLE_METADATA")
include(":submodule")
@@ -0,0 +1,18 @@
buildscript {
repositories {
{{kts_kotlin_plugin_repositories}}
}
}
repositories {
{{kts_kotlin_plugin_repositories}}
}
plugins {
kotlin("multiplatform")
}
kotlin {
js()
jvm()
}