Skip to content

Commit

Permalink
took publishing-configuration.gradle.kts from kompiledb
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Jul 28, 2023
1 parent 201ba16 commit 6223bca
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 281 deletions.
26 changes: 8 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import com.saveourtool.osv4k.buildutils.configureDiktat
import com.saveourtool.osv4k.buildutils.configureVersioning
import com.saveourtool.osv4k.buildutils.createDetektTask

plugins {
// alias(libs.plugins.kotlin.multiplatform)
// alias(libs.plugins.kotlin.plugin.serialization)
id("com.saveourtool.osv4k.buildutils.kotlin-library")
id("com.saveourtool.osv4k.buildutils.publishing-configuration")
}

group = "com.saveourtool.osv4k"
Expand All @@ -14,11 +11,6 @@ repositories {
mavenCentral()
}

// version generation
configureVersioning()
// checks and validations

configureDiktat()
createDetektTask()

kotlin {
Expand All @@ -29,9 +21,11 @@ kotlin {
kotlinOptions.jvmTarget = "1.8"
}
}
linuxX64()
mingwX64()
macosX64()
val nativeTargets = setOf(
linuxX64(),
mingwX64(),
macosX64(),
)
sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -48,12 +42,8 @@ kotlin {
val commonNonJvmMain by creating {
dependsOn(commonMain)
}
listOf(
"linuxX64",
"mingwX64",
"macosX64",
).forEach { nonJvmTarget ->
getByName("${nonJvmTarget}Main").dependsOn(commonNonJvmMain)
nativeTargets.forEach { nativeTarget ->
getByName("${nativeTarget.name}Main").dependsOn(commonNonJvmMain)
}
@Suppress("UNUSED_VARIABLE")
val jvmMain by getting {
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(libs.diktat.gradle.plugin)
implementation(libs.detekt.gradle.plugin)
implementation(libs.kotlin.plugin.serialization)
implementation("io.github.gradle-nexus:publish-plugin:1.3.0")
implementation("org.ajoberstar.reckon:reckon-gradle:0.18.0")
implementation(libs.dokka.gradle.plugin)
implementation(libs.gradle.nexus.publish.plugin)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun Project.configureJacoco() {
apply<JacocoPlugin>()

configure<JacocoPluginExtension> {
toolVersion = "0.8.8"
toolVersion = JacocoPlugin.DEFAULT_JACOCO_VERSION
}

val kotlin: KotlinMultiplatformExtension = extensions.getByType()
Expand All @@ -34,11 +34,10 @@ fun Project.configureJacoco() {
}

val configure: JacocoReport.() -> Unit = {
dependsOn(jvmTestTask)
executionData(jvmTestTask.extensions.getByType(JacocoTaskExtension::class.java).destinationFile)
// todo: include platform-specific source sets
additionalSourceDirs(
kotlin.sourceSets["commonMain"].kotlin.sourceDirectories +
kotlin.sourceSets["commonNonJvmMain"].kotlin.sourceDirectories
kotlin.sourceSets["commonMain"].kotlin.sourceDirectories
)
classDirectories.setFrom(fileTree("$buildDir/classes/kotlin/jvm/main").apply {
exclude("**/*\$\$serializer.class")
Expand All @@ -50,16 +49,15 @@ fun Project.configureJacoco() {
}

// `application` plugin creates jacocoTestReport task in plugin section (this is definitely incorrect behavior)
// AFTER that in "com.saveourtool.save.buildutils.kotlin-library" we try to register this task once again and fail
// AFTER that in "com.saveourtool.osv4k.buildutils.kotlin-library" we try to register this task once again and fail
// so the order of plugins in `apply` is critically important
val jacocoTestReportTask = if (project.name == "save-cli") {
val jacocoTestReportTask by tasks.named("jacocoTestReport", configure)
val jacocoTestReportTask = if (project.name == "osv4k") {
val jacocoTestReportTask by tasks.register("jacocoTestReport", configure)
jacocoTestReportTask
} else {
val jacocoTestReportTask by tasks.register("jacocoTestReport", configure)
jacocoTestReportTask
}

jvmTestTask.finalizedBy(jacocoTestReportTask)
jacocoTestReportTask.dependsOn(jvmTestTask)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.saveourtool.osv4k.buildutils

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

plugins {
Expand All @@ -17,101 +16,13 @@ plugins {

kotlin {
jvmToolchain {
this.languageVersion.set(JavaLanguageVersion.of("11"))
}
jvm {
compilations.all {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all"
}
}
}
val nativeTargets = listOf(linuxX64(), mingwX64(), macosX64())
if (project.name == "save-common") {
// additionally, save-common should be available for JS too
// fixme: shouldn't rely on hardcoded project name here
js(IR).browser()

// store yarn.lock in the root directory
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
lockFileDirectory = rootProject.projectDir
}
}

if (hasProperty("disableRedundantTargets") && (property("disableRedundantTargets") as String?) != "false") {
// with this flag we exclude targets that are present on multiple OS to speed up build
val currentOs = DefaultNativePlatform.getCurrentOperatingSystem()
val redundantTarget: String? = when {
currentOs.isWindows -> "linuxX64"
currentOs.isMacOsX -> "linuxX64"
currentOs.isLinux -> null
else -> throw GradleException("Unknown operating system ${currentOs.name}")
}
tasks.matching { redundantTarget != null && it.name.contains(redundantTarget, ignoreCase = true) }
.configureEach {
logger.lifecycle("Disabling task :${project.name}:$name on host $currentOs")
enabled = false
}
}

/*
* Common structure for MPP libraries:
* common
* |
* nonJs
* / \
* native JVM
* / | \
* linux mingw macos
*/
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
val commonMain by getting
val commonTest by getting {
dependencies {
implementation("io.kotest:kotest-assertions-core:5.6.2")
}
}
val commonNonJsMain by creating {
dependsOn(commonMain)
}
val commonNonJsTest by creating {
dependsOn(commonTest)
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting {
dependsOn(commonNonJsMain)
}
val jvmTest by getting {
dependsOn(commonNonJsTest)
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}
}
val nativeMain by creating {
dependsOn(commonNonJsMain)
}
val nativeTest by creating {
dependsOn(commonNonJsTest)
}
nativeTargets.forEach {
getByName("${it.name}Main").dependsOn(nativeMain)
}
nativeTargets.forEach {
getByName("${it.name}Test").dependsOn(nativeTest)
}
languageVersion.set(JavaLanguageVersion.of("17"))
}
}

configureVersioning()
// withJava() creates a task for jacoco
// configureJacoco()
configurePublishing()
configureDiktat()
configureDetekt()

Expand Down
Loading

0 comments on commit 6223bca

Please sign in to comment.