Skip to content

Commit

Permalink
build.gradle.kts rebuilt from ground up to ensure MVJ understands how…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Mikael Vejdemo-Johansson committed Nov 9, 2023
1 parent 23386f5 commit c361757
Showing 1 changed file with 66 additions and 69 deletions.
135 changes: 66 additions & 69 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,78 +25,46 @@ repositories {
maven("https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven")
}

tasks.withType<DokkaTask>().configureEach {
dependencies {
dokkaPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10")
dokkaPlugin("org.jetbrains.dokka:mathjax-plugin:1.9.10")
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
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>("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 {
Expand All @@ -104,15 +74,42 @@ 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")
}
}
}
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dependencies {
dokkaPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10")
dokkaPlugin("org.jetbrains.dokka:mathjax-plugin:1.9.10")
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
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/**")
}
}

0 comments on commit c361757

Please sign in to comment.