Skip to content
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

Use targets hierarchy API #4349

Merged
merged 3 commits into from
Sep 30, 2024
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
13 changes: 2 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,15 @@ doctor {
enableTestCaching = false
}

allprojects {
subprojects {
group = "io.ktor"
version = configuredVersion
extra["hostManager"] = HostManager()

setupTrainForSubproject()

repositories {
mavenLocal()
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/dev")
}

val nonDefaultProjectStructure: List<String> by rootProject.extra
if (nonDefaultProjectStructure.contains(project.name)) return@allprojects
if (nonDefaultProjectStructure.contains(project.name)) return@subprojects

apply(plugin = "kotlin-multiplatform")
apply(plugin = "atomicfu-conventions")
Expand All @@ -145,9 +138,7 @@ allprojects {
if (!skipPublish.contains(project.name)) {
configurePublication()
}
}

subprojects {
configureCodestyle()
}

Expand Down
4 changes: 4 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ dependencies {
implementation(libs.logback.classic)
implementation(libs.tomlj)
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfu.get()}")

// A hack to make version catalogs accessible from buildSrc sources
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pluginManagement {

dependencyResolutionManagement {
versionCatalogs {
val libs by creating {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
Expand Down
8 changes: 5 additions & 3 deletions buildSrc/src/main/kotlin/CommonConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import internal.*
import org.gradle.api.*
import org.gradle.kotlin.dsl.*

Expand All @@ -9,13 +11,13 @@ fun Project.configureCommon() {
sourceSets {
commonMain {
dependencies {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}")
api(libs.kotlinx.coroutines.core)
}
}

commonTest {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotlin.test)
}
}
}
Expand Down
62 changes: 30 additions & 32 deletions buildSrc/src/main/kotlin/JsConfig.kt
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("UNUSED_VARIABLE")

import internal.*
import org.gradle.api.*
import org.gradle.internal.extensions.stdlib.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.targets.js.ir.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import java.io.*
import kotlin.toString

fun Project.configureJs() {
configureJsTasks()

kotlin {
js {
if (project.targetIsEnabled("js.nodeJs")) nodejs { useMochaForTests() }
if (project.targetIsEnabled("js.browser")) browser { useKarmaForTests() }

binaries.library()
}

sourceSets {
val jsTest by getting {
jsTest {
dependencies {
implementation(npm("puppeteer", Versions.puppeteer))
implementation(npm("puppeteer", libs.versions.puppeteer.get()))
}
}
}
}

configureJsTestTasks()
configureJsTestTasks(target = "js")
}

private fun Project.configureJsTasks() {
kotlin {
js {
if (project.targetIsEnabled("js.nodeJs")) {
nodejs {
testTask {
useMocha {
timeout = "10000"
}
}
}
}

(this as KotlinJsIrTarget).whenBrowserConfigured {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
}
}
}
internal fun KotlinJsSubTargetDsl.useMochaForTests() {
testTask {
useMocha {
timeout = "10000"
}
}
}

binaries.library()
internal fun KotlinJsSubTargetDsl.useKarmaForTests() {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
}
}
}

private fun Project.configureJsTestTasks() {
internal fun Project.configureJsTestTasks(target: String) {
val shouldRunJsBrowserTest = !hasProperty("teamcity") || hasProperty("enable-js-tests")
if (shouldRunJsBrowserTest) return

tasks.maybeNamed("cleanJsBrowserTest") { onlyIf { false } }
tasks.maybeNamed("jsBrowserTest") { onlyIf { false } }
val capitalizedTarget = target.replaceFirstChar { it.titlecase() }
tasks.maybeNamed("clean${capitalizedTarget}BrowserTest") { onlyIf { false } }
tasks.maybeNamed("${target}BrowserTest") { onlyIf { false } }
}
38 changes: 14 additions & 24 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import internal.*
import org.gradle.api.*
import org.gradle.api.tasks.testing.*
import org.gradle.jvm.tasks.*
Expand All @@ -15,41 +16,30 @@ fun Project.configureJvm() {
else -> 8
}

val jvm = kotlin.jvm()
kotlin {
jvm()

kotlin.sourceSets {
val jvmMain by getting {
dependencies {
if (jdk > 6) {
api("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}")
sourceSets {
jvmMain {
dependencies {
api(libs.slf4j.api)
}
if (jdk > 7) {
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Versions.kotlin}")
api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${Versions.coroutines}") {
exclude(module = "kotlin-stdlib")
exclude(module = "kotlin-stdlib-jvm")
exclude(module = "kotlin-stdlib-jdk8")
exclude(module = "kotlin-stdlib-jdk7")
}
}

api("org.slf4j:slf4j-api:${Versions.slf4j}")
}
}

val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${Versions.junit}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:${Versions.coroutines}")
jvmTest {
dependencies {
implementation(libs.kotlin.test.junit5)
implementation(libs.junit)
implementation(libs.kotlinx.coroutines.debug)
}
}
}
}

tasks.register<Jar>("jarTest") {
dependsOn(tasks.named("jvmTestClasses"))
archiveClassifier = "test"
from(jvm.compilations.named("test").map { it.output })
from(kotlin.jvm().compilations.named("test").map { it.output })
}

configurations {
Expand Down
Loading