From c36175789d29a766644faf38cc4adde6fdbac9de Mon Sep 17 00:00:00 2001 From: Mikael Vejdemo-Johansson Date: Wed, 8 Nov 2023 23:31:39 -0800 Subject: [PATCH] build.gradle.kts rebuilt from ground up to ensure MVJ understands how everything connects. Also, shadowJar plugin and task introduced to produce single JAR file with both library and all dependencies. We now get a single JAR file that can be loaded as library and contains everything the code needs. --- build.gradle.kts | 135 +++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b619343c..f8b788ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,18 @@ -import org.jetbrains.dokka.gradle.DokkaTask +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { kotlin("multiplatform") version "1.9.20" + `java` + `java-library` + `java-library-distribution` id("org.jetbrains.dokka") version "1.9.10" id("io.kotest.multiplatform") version "5.7.2" - id("com.google.devtools.ksp") version "1.8.21-1.0.11" id("org.jlleitschuh.gradle.ktlint") version "11.6.1" - `java-library-distribution` + id("com.github.johnrengelman.shadow") version "8.1.1" } group = "org.appliedtopology" -version = "1.0-SNAPSHOT" +version = "0.1-DEV" distributions { main { @@ -23,78 +25,46 @@ repositories { maven("https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven") } -tasks.withType().configureEach { - dependencies { - dokkaPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10") - dokkaPlugin("org.jetbrains.dokka:mathjax-plugin:1.9.10") - } -} - -tasks.withType().configureEach { - useJUnitPlatform() -} - -configure { - version.set("1.0.1") - debug.set(true) - verbose.set(true) - android.set(false) - outputToConsole.set(true) - outputColorName.set("RED") - ignoreFailures.set(true) - enableExperimentalRules.set(true) - additionalEditorconfig.set( // not supported until ktlint 0.49 - mapOf( - "ktlint_standard_no-wildcard-imports" to "disabled", - ), - ) - filter { - exclude("**/generated/**") - include("**/kotlin/**") - } -} - kotlin { jvmToolchain(17) + jvm { - compilations.all { - kotlinOptions { - jvmTarget = "17" + // We have to configure the shadowJar task explicitly, because + // we are doing a multi-platform build + // https://stackoverflow.com/questions/63426211/kotlin-multiplatform-shadowjar-gradle-plugin-creates-empty-jar + compilations.named("main") { + tasks { + val shadowJar = + register("ShadowJar") { + group = "distribution" + from(output) + configurations = listOf(runtimeDependencyFiles) + archiveClassifier.set("all") + dependsOn("jvmJar") + dependsOn("jvmMainClasses") + } } } - withJava() - testRuns["test"].executionTask.configure { - useJUnitPlatform() - } } + js(IR) { - browser { - commonWebpackConfig { - // cssSupport.enabled = true - } - } + browser() + nodejs() + } + + val hostOS = System.getProperty("os.name") + when { + hostOS.startsWith("Windows") -> mingwX64("native") + hostOS == "Linux" -> linuxX64("native") + else -> println("Not configured to build targeting native platform $hostOS") } - val hostOs = System.getProperty("os.name") - val isMingwX64 = hostOs.startsWith("Windows") - val nativeTarget = - when { - // hostOs == "Mac OS X" -> macosX64("native") - hostOs == "Linux" -> linuxX64("native") - isMingwX64 -> mingwX64("native") - else -> println("Host OS is not supported in Kotlin/Native.") - } sourceSets { val commonMain by getting { dependencies { - api(kotlin("stdlib")) - implementation(kotlin("script-runtime")) - implementation(platform("io.arrow-kt:arrow-stack:1.2.0")) - implementation("io.arrow-kt:arrow-core") - implementation("io.arrow-kt:arrow-fx-coroutines") - implementation("io.arrow-kt:arrow-optics") - api("space.kscience:kmath-core:0.3.1") - api("space.kscience:kmath-tensors:0.3.1") + implementation("io.arrow-kt:arrow-core:1.2.0") + implementation("space.kscience:kmath-core:0.3.1") + implementation("space.kscience:kmath-tensors:0.3.1") } } val commonTest by getting { @@ -104,11 +74,6 @@ kotlin { implementation("io.kotest:kotest-property:5.7.2") } } - val jvmMain by getting { - dependencies { - implementation(kotlin("script-runtime")) - } - } val jvmTest by getting { dependencies { implementation("io.kotest:kotest-runner-junit5:5.7.2") @@ -116,3 +81,35 @@ kotlin { } } } + +tasks.withType().configureEach { + dependencies { + dokkaPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10") + dokkaPlugin("org.jetbrains.dokka:mathjax-plugin:1.9.10") + } +} + +tasks.withType().configureEach { + useJUnitPlatform() +} + +configure { + version.set("1.0.1") + debug.set(true) + verbose.set(true) + android.set(false) + outputToConsole.set(true) + outputColorName.set("RED") + ignoreFailures.set(true) + enableExperimentalRules.set(true) + additionalEditorconfig.set( + // not supported until ktlint 0.49 + mapOf( + "ktlint_standard_no-wildcard-imports" to "disabled", + ), + ) + filter { + exclude("**/generated/**") + include("**/kotlin/**") + } +}