diff --git a/.idea/detekt.xml b/.idea/detekt.xml
index 27c8e5b..4514270 100644
--- a/.idea/detekt.xml
+++ b/.idea/detekt.xml
@@ -11,6 +11,8 @@
+
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index d9ec602..48d90f2 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,7 +1,7 @@
import nl.littlerobots.vcu.plugin.versionCatalogUpdate
-import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
@@ -24,9 +24,20 @@ buildscript {
}
}
+
allprojects {
group = Config.artifactId
version = Config.versionName
+ tasks.withType().configureEach {
+ compilerOptions {
+ jvmTarget.set(Config.jvmTarget)
+ languageVersion.set(Config.kotlinVersion)
+ freeCompilerArgs.apply {
+ addAll(Config.jvmCompilerArgs)
+ }
+ optIn.addAll(Config.optIns.map { "-opt-in=$it" })
+ }
+ }
}
atomicfu {
@@ -44,22 +55,19 @@ subprojects {
}
tasks {
- withType {
- val className =
- "org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask"
-
- @Suppress("UNCHECKED_CAST")
- val taskClass = Class.forName(className) as Class
- parent?.subprojects?.forEach {
- dependsOn(it.tasks.withType(taskClass))
- }
+ withType().configureEach {
+ useJUnitPlatform()
+ filter { isFailOnNoMatchingTests = true }
}
-
register("dokkaJavadocJar") {
dependsOn(dokkaJavadoc)
from(dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
+
+ register("emptyJavadocJar") {
+ archiveClassifier.set("javadoc")
+ }
}
}
@@ -144,10 +152,8 @@ tasks {
distributionType = Wrapper.DistributionType.BIN
}
}
-plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
- extensions.findByType()!!.run {
- yarnLockMismatchReport = YarnLockMismatchReport.WARNING
- reportNewYarnLock = true
- yarnLockAutoReplace = false
- }
+extensions.findByType()?.run {
+ yarnLockMismatchReport = YarnLockMismatchReport.WARNING
+ reportNewYarnLock = true
+ yarnLockAutoReplace = false
}
diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt
index 6b63a06..ae35138 100644
--- a/buildSrc/src/main/kotlin/Config.kt
+++ b/buildSrc/src/main/kotlin/Config.kt
@@ -7,6 +7,7 @@
import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
object Config {
@@ -18,8 +19,14 @@ object Config {
const val majorRelease = 1
const val minorRelease = 3
const val patch = 0
- const val versionName = "$majorRelease.$minorRelease.$patch"
+ const val postfix = ""
+ const val versionName = "$majorRelease.$minorRelease.$patch$postfix"
+ const val url = "https://github.com/respawn-app/kmputils"
+ const val licenseName = "The Apache Software License, Version 2.0"
+ const val licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ const val scmUrl = "https://github.com/respawn-app/kmmutils.git"
+ const val description = """A collection of Kotlin Multiplatform essentials"""
// kotlin
val optIns = listOf(
@@ -36,12 +43,13 @@ object Config {
addAll(compilerArgs)
add("-Xjvm-default=all") // enable all jvm optimizations
add("-Xcontext-receivers")
+ add("-Xstring-concat=inline")
addAll(optIns.map { "-opt-in=$it" })
}
val jvmTarget = JvmTarget.JVM_11
val javaVersion = JavaVersion.VERSION_11
- val kotlinVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
+ val kotlinVersion = KotlinVersion.KOTLIN_1_9
const val compileSdk = 34
const val targetSdk = compileSdk
const val minSdk = 21
diff --git a/buildSrc/src/main/kotlin/ConfigureAndroid.kt b/buildSrc/src/main/kotlin/ConfigureAndroid.kt
index c632713..2a59b72 100644
--- a/buildSrc/src/main/kotlin/ConfigureAndroid.kt
+++ b/buildSrc/src/main/kotlin/ConfigureAndroid.kt
@@ -4,8 +4,12 @@ import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
-fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
+fun Project.configureAndroid(
+ commonExtension: CommonExtension<*, *, *, *, *, *>,
+) = commonExtension.apply {
compileSdk = Config.compileSdk
+ // val libs by versionCatalog
+
defaultConfig {
minSdk = Config.minSdk
testInstrumentationRunner = Config.testRunner
@@ -42,13 +46,11 @@ fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
}
packaging {
- resources {
- excludes += setOf(
- "DebugProbesKt.bin",
- "/META-INF/{AL2.0,LGPL2.1}",
- "/META-INF/versions/9/previous-compilation-data.bin"
- )
- }
+ resources.excludes += listOf(
+ "/META-INF/{AL2.0,LGPL2.1}",
+ "DebugProbesKt.bin",
+ "META-INF/versions/9/previous-compilation-data.bin"
+ )
}
testOptions {
@@ -64,13 +66,22 @@ fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
}
}
}
+
+ // composeOptions {
+ // kotlinCompilerExtensionVersion = libs.requireVersion("compose-compiler")
+ // useLiveLiterals = true
+ // }
}
fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
- configureAndroid()
+ configureAndroid(this)
+
+ testFixtures {
+ enable = true
+ }
- kotlinOptions {
- freeCompilerArgs += "-Xexplicit-api=strict"
+ defaultConfig {
+ consumerProguardFiles(file(Config.consumerProguardFile))
}
buildTypes {
@@ -82,10 +93,6 @@ fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
}
}
- defaultConfig {
- consumerProguardFiles(file(Config.consumerProguardFile))
- }
-
libraryVariants.all {
sourceSets {
getByName(name) {
diff --git a/buildSrc/src/main/kotlin/ConfigureMultiplatform.kt b/buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
index 15eba14..d652db8 100644
--- a/buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
+++ b/buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
@@ -41,7 +41,6 @@ fun Project.configureMultiplatform(
if (jvm) jvm()
- if (iOs) {
sequence {
if (iOs) {
yield(iosX64())
@@ -69,7 +68,6 @@ fun Project.configureMultiplatform(
binaryOption("bundleVersion", Config.versionName)
baseName = Config.artifactId
}
- }
}
sourceSets.apply {
diff --git a/buildSrc/src/main/kotlin/ConfigurePublication.kt b/buildSrc/src/main/kotlin/ConfigurePublication.kt
index 33c052c..39e6fad 100644
--- a/buildSrc/src/main/kotlin/ConfigurePublication.kt
+++ b/buildSrc/src/main/kotlin/ConfigurePublication.kt
@@ -8,6 +8,7 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.get
+import org.gradle.kotlin.dsl.maybeCreate
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.Sign
@@ -17,51 +18,47 @@ import org.gradle.plugins.signing.Sign
fun Project.publishMultiplatform() {
val properties by localProperties
val isReleaseBuild = properties["release"]?.toString().toBoolean()
- val javadocJar = tasks.named("dokkaJavadocJar")
+
+ val javadocTask = tasks.named("emptyJavadocJar") // TODO: dokka does not support kmp javadocs yet
afterEvaluate {
requireNotNull(extensions.findByType()).apply {
sonatypeRepository(isReleaseBuild, properties)
publications.withType().configureEach {
- artifact(javadocJar)
+ artifact(javadocTask)
configurePom()
configureVersion(isReleaseBuild)
}
}
- signPublications(properties)
+ signPublications(isReleaseBuild, properties)
}
tasks.withType {
- dependsOn(javadocJar)
+ dependsOn(javadocTask)
}
}
/**
* Publish the android artifact
*/
-fun Project.publishAndroid() {
- val properties by localProperties
- requireNotNull(extensions.findByType()).apply {
- publishing {
- singleVariant(Config.publishingVariant) {
- withSourcesJar()
- withJavadocJar()
- }
- }
- testFixtures {
- enable = true
+fun Project.publishAndroid(ext: LibraryExtension) = with(ext) {
+ publishing {
+ singleVariant(Config.publishingVariant) {
+ withSourcesJar()
+ withJavadocJar()
}
}
afterEvaluate {
+ val properties by localProperties
val isReleaseBuild = properties["release"]?.toString().toBoolean()
requireNotNull(extensions.findByType()).apply {
sonatypeRepository(isReleaseBuild, properties)
publications {
- create(Config.publishingVariant, MavenPublication::class.java) {
+ maybeCreate(Config.publishingVariant, MavenPublication::class).apply {
from(components[Config.publishingVariant])
suppressPomMetadataWarningsFor(Config.publishingVariant)
groupId = rootProject.group.toString()
@@ -72,7 +69,7 @@ fun Project.publishAndroid() {
}
}
}
- signPublications(properties)
+ signPublications(isReleaseBuild, properties)
}
tasks.withType().configureEach {
diff --git a/buildSrc/src/main/kotlin/PublishingExt.kt b/buildSrc/src/main/kotlin/PublishingExt.kt
index ed6b56f..ebabbe6 100644
--- a/buildSrc/src/main/kotlin/PublishingExt.kt
+++ b/buildSrc/src/main/kotlin/PublishingExt.kt
@@ -20,13 +20,13 @@ internal fun MavenPublication.configureVersion(release: Boolean) {
internal fun MavenPublication.configurePom() = pom {
name.set(Config.artifact)
- description.set("A collection of Kotlin Multiplatform essentials")
- url.set("https://github.com/respawn-app/kmmutils")
+ description.set(Config.description)
+ url.set(Config.url)
licenses {
license {
- name.set("The Apache Software License, Version 2.0")
- url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
+ name.set(Config.licenseName)
+ url.set(Config.licenseUrl)
distribution.set("repo")
}
}
@@ -40,12 +40,10 @@ internal fun MavenPublication.configurePom() = pom {
organizationUrl.set(url)
}
}
- scm {
- url.set("https://github.com/respawn-app/kmmutils.git")
- }
+ scm { url.set(Config.scmUrl) }
}
-internal fun PublishingExtension.sonatypeRepository(release: Boolean, properties: Properties) = repositories {
+internal fun PublishingExtension.sonatypeRepository(release: Boolean, localProps: Properties) = repositories {
maven {
name = "sonatype"
url = URI(
@@ -56,22 +54,20 @@ internal fun PublishingExtension.sonatypeRepository(release: Boolean, properties
}
)
credentials {
- username = properties["sonatypeUsername"]?.toString()
- password = properties["sonatypePassword"]?.toString()
+ username = localProps["sonatypeUsername"]?.toString()
+ password = localProps["sonatypePassword"]?.toString()
}
}
}
-internal fun Project.signPublications(properties: Properties) =
+internal fun Project.signPublications(isRelease: Boolean, localProps: Properties) =
requireNotNull(extensions.findByType()).apply {
- val isReleaseBuild = properties["release"]?.toString().toBoolean()
-
val publishing = requireNotNull(extensions.findByType())
- val signingKey: String? = properties["signing.key"]?.toString()
- val signingPassword: String? = properties["signing.password"]?.toString()
+ val signingKey: String? = localProps["signing.key"]?.toString()
+ val signingPassword: String? = localProps["signing.password"]?.toString()
- isRequired = isReleaseBuild
+ isRequired = isRelease
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
@@ -81,7 +77,7 @@ internal fun Project.signPublications(properties: Properties) =
tasks.run {
withType().configureEach {
- onlyIf { isReleaseBuild }
+ onlyIf { isRelease }
}
withType().configureEach {
diff --git a/buildSrc/src/main/kotlin/Util.kt b/buildSrc/src/main/kotlin/Util.kt
index 322bbcd..ccef2f7 100644
--- a/buildSrc/src/main/kotlin/Util.kt
+++ b/buildSrc/src/main/kotlin/Util.kt
@@ -5,14 +5,11 @@
"UndocumentedPublicFunction"
)
-import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
-import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.getByType
import org.gradle.plugin.use.PluginDependency
-import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.io.File
import java.io.FileInputStream
import java.util.Base64
@@ -34,13 +31,8 @@ fun VersionCatalog.requirePlugin(alias: String) = findPlugin(alias).get().toStri
fun VersionCatalog.requireLib(alias: String) = findLibrary(alias).get()
fun VersionCatalog.requireBundle(alias: String) = findBundle(alias).get()
fun VersionCatalog.requireVersion(alias: String) = findVersion(alias).get().toString()
-
val org.gradle.api.provider.Provider.id: String get() = get().pluginId
-fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
- (this as ExtensionAware).extensions.configure("kotlinOptions", block)
-}
-
/**
* Creates a java array initializer code for a list of strings.
* Example: { "a", "b", "c" }
diff --git a/buildSrc/src/main/kotlin/pro.respawn.android-library.gradle.kts b/buildSrc/src/main/kotlin/pro.respawn.android-library.gradle.kts
index 307a2fe..7d34e31 100644
--- a/buildSrc/src/main/kotlin/pro.respawn.android-library.gradle.kts
+++ b/buildSrc/src/main/kotlin/pro.respawn.android-library.gradle.kts
@@ -5,8 +5,16 @@ plugins {
signing
}
+kotlin {
+ explicitApi()
+}
+
android {
configureAndroidLibrary(this)
-}
+ publishAndroid(this)
-publishAndroid()
+ kotlinOptions {
+ jvmTarget = Config.jvmTarget.target
+ languageVersion = Config.kotlinVersion.version
+ }
+}
diff --git a/buildSrc/src/main/kotlin/pro.respawn.shared-library.gradle.kts b/buildSrc/src/main/kotlin/pro.respawn.shared-library.gradle.kts
index 57e8f70..84be3c4 100644
--- a/buildSrc/src/main/kotlin/pro.respawn.shared-library.gradle.kts
+++ b/buildSrc/src/main/kotlin/pro.respawn.shared-library.gradle.kts
@@ -1,7 +1,16 @@
plugins {
kotlin("multiplatform")
+ id("com.android.library")
id("maven-publish")
signing
}
+kotlin {
+ configureMultiplatform(this)
+}
+
+android {
+ configureAndroidLibrary(this)
+}
+
publishMultiplatform()
diff --git a/common/build.gradle.kts b/common/build.gradle.kts
index 1ac05b6..2f54f60 100644
--- a/common/build.gradle.kts
+++ b/common/build.gradle.kts
@@ -1,8 +1,6 @@
-@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("pro.respawn.shared-library")
}
-
-kotlin {
- configureMultiplatform(this, android = false)
+android {
+ namespace = "${Config.namespace}.common"
}
diff --git a/coroutines/build.gradle.kts b/coroutines/build.gradle.kts
index f3b6fe7..001416b 100644
--- a/coroutines/build.gradle.kts
+++ b/coroutines/build.gradle.kts
@@ -2,11 +2,9 @@ plugins {
id("pro.respawn.shared-library")
id(libs.plugins.atomicfu.id)
}
-
-kotlin {
- configureMultiplatform(this, android = false)
+android {
+ namespace = "${Config.namespace}.coroutines"
}
-
dependencies {
commonMainApi(libs.kotlinx.coroutines.core)
commonMainImplementation(libs.kotlinx.atomicfu)
diff --git a/datetime/build.gradle.kts b/datetime/build.gradle.kts
index 2b754b1..bab76ec 100644
--- a/datetime/build.gradle.kts
+++ b/datetime/build.gradle.kts
@@ -2,8 +2,8 @@ plugins {
id("pro.respawn.shared-library")
}
-kotlin {
- configureMultiplatform(this, android = false)
+android {
+ namespace = "${Config.namespace}.datetime"
}
dependencies {
diff --git a/inputforms/build.gradle.kts b/inputforms/build.gradle.kts
index b45ba67..904c49f 100644
--- a/inputforms/build.gradle.kts
+++ b/inputforms/build.gradle.kts
@@ -1,14 +1,10 @@
plugins {
id("pro.respawn.shared-library")
}
-
-kotlin {
- configureMultiplatform(this, android = false)
- sourceSets.jvmTest.dependencies {
- implementation(libs.bundles.unittest)
- }
+android {
+ namespace = "${Config.namespace}.inputforms"
}
-
dependencies {
commonMainApi(projects.common)
+ jvmTestImplementation(libs.bundles.unittest)
}