Skip to content

Migrated shared build logic from buildSrc to composite builds #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts → build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

plugins {
`kotlin-dsl`
`kotlin-dsl`
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation(libs.kotlin.gradle.plugin)
implementation(libs.kotlin.gradle.plugin)
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright 2017-2023 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
*/

import org.gradle.kotlin.dsl.kotlin
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import kotlin.jvm.optionals.getOrNull

plugins {
kotlin("multiplatform")
}

kotlin {

val versionCatalog: VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
jvmToolchain {
val javaVersion = versionCatalog.findVersion("java").getOrNull()?.requiredVersion
?: throw GradleException("Version 'java' is not specified in the version catalog")
languageVersion.set(JavaLanguageVersion.of(javaVersion))
}

jvm {
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}

js(IR) {
browser {
testTask {
filter.setExcludePatterns("*SmokeFileTest*")
}
}
}

sourceSets {
commonTest {
dependencies {
implementation(kotlin("test"))
}
}
}

explicitApi()
sourceSets.configureEach {
configureSourceSet()
}

configureNativePlatforms()

val nativeTargets = nativeTargets()
sourceSets {
createSourceSet("nativeMain", parent = commonMain.get(), children = nativeTargets)
createSourceSet("nativeTest", parent = commonTest.get(), children = nativeTargets)
}
}

fun KotlinSourceSet.configureSourceSet() {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val platform = name.dropLast(4)
kotlin.srcDir("$platform/$srcDir")
if (name == "jvmMain") {
resources.srcDir("$platform/resources")
} else if (name == "jvmTest") {
resources.srcDir("$platform/test-resources")
}
languageSettings {
progressiveMode = true
}
}

/**
* Creates a source set for a directory that isn't already a built-in platform. Use this to create
* custom shared directories like `nonJvmMain` or `unixMain`.
*/
fun NamedDomainObjectContainer<KotlinSourceSet>.createSourceSet(
name: String,
parent: KotlinSourceSet? = null,
children: List<String> = listOf()
): KotlinSourceSet {
val result = create(name)

if (parent != null) {
result.dependsOn(parent)
}

val suffix = when {
name.endsWith("Main") -> "Main"
name.endsWith("Test") -> "Test"
else -> error("unexpected source set name: ${name}")
}

for (childTarget in children) {
val childSourceSet = get("${childTarget}$suffix")
childSourceSet.dependsOn(result)
}

return result
}

fun KotlinMultiplatformExtension.configureNativePlatforms() {
iosX64()
iosArm64()
iosSimulatorArm64()
tvosX64()
tvosArm64()
tvosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosX64()
watchosSimulatorArm64()
watchosDeviceArm64()
linuxArm64()
androidNativeArm32()
androidNativeArm64()
androidNativeX64()
androidNativeX86()
// Required to generate tests tasks: https://youtrack.jetbrains.com/issue/KT-26547
linuxX64()
macosX64()
macosArm64()
mingwX64()
}

fun nativeTargets(): List<String> {
return appleTargets() + linuxTargets() + mingwTargets() + androidTargets()
}

fun appleTargets() = listOf(
"iosArm64",
"iosX64",
"iosSimulatorArm64",
"macosX64",
"macosArm64",
"tvosArm64",
"tvosX64",
"tvosSimulatorArm64",
"watchosArm32",
"watchosArm64",
"watchosX64",
"watchosSimulatorArm64",
"watchosDeviceArm64"
)

fun mingwTargets() = listOf(
"mingwX64"
)

fun linuxTargets() = listOf(
"linuxX64",
"linuxArm64"
)

fun androidTargets() = listOf(
"androidNativeArm32",
"androidNativeArm64",
"androidNativeX64",
"androidNativeX86"
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file.
*/

import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.*
import org.gradle.api.file.*
import org.gradle.api.provider.*
import org.gradle.api.publish.maven.*
import org.gradle.jvm.tasks.*
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.*
import java.net.*
import org.gradle.jvm.tasks.Jar
import java.net.URI

plugins {
`maven-publish`
signing
}

publishing {
repositories {
configureMavenPublication(project)
}

val javadocJar = project.configureEmptyJavadocArtifact()
publications.withType(MavenPublication::class).all {
pom.configureMavenCentralMetadata(project)
signPublicationIfKeyPresent(project, this)
artifact(javadocJar)
}

tasks.withType<PublishToMavenRepository>().configureEach {
dependsOn(tasks.withType<Sign>())
}
}

// Pom configuration
infix fun <T> Property<T>.by(value: T) {
Expand Down Expand Up @@ -103,6 +118,6 @@ fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication)
}
}

private fun Project.getSensitiveProperty(name: String): String? {
fun Project.getSensitiveProperty(name: String): String? {
return project.findProperty(name) as? String ?: System.getenv(name)
}
44 changes: 2 additions & 42 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile

plugins {
id("kotlinx-io-publish") apply false

alias(libs.plugins.bcv)
alias(libs.plugins.dokka)
`maven-publish`
signing
}

buildscript {
dependencies {
classpath(libs.kotlin.gradle.plugin)
}

repositories {
mavenCentral()
gradlePluginPortal()
}
}

allprojects {
Expand All @@ -31,35 +20,6 @@ allprojects {
}
}

apply(plugin = "maven-publish")
apply(plugin = "signing")

subprojects {
if (name.contains("benchmark")) {
return@subprojects
}

repositories {
mavenCentral()
}

apply(plugin = "maven-publish")
apply(plugin = "signing")

publishing {
repositories {
configureMavenPublication(project)
}

val javadocJar = project.configureEmptyJavadocArtifact()
publications.withType(MavenPublication::class).all {
pom.configureMavenCentralMetadata(project)
signPublicationIfKeyPresent(project, this)
artifact(javadocJar)
}
}
}

subprojects {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
Expand Down
97 changes: 0 additions & 97 deletions buildSrc/src/main/kotlin/Platforms.kt

This file was deleted.

Loading