Skip to content

Commit

Permalink
Merge pull request #12 from respawn-app/1.3.0
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
Nek-12 committed Dec 11, 2023
2 parents fce5b8d + ce4488e commit cf4acd1
Show file tree
Hide file tree
Showing 29 changed files with 638 additions and 235 deletions.
1 change: 1 addition & 0 deletions .github/ci-gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ org.gradle.daemon=false
org.gradle.workers.max=2
org.gradle.unsafe.configuration-cache=false
android.disableResourceValidation=false
kotlinx.atomicfu.enableJvmIrTransformation=true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enjoy the expanded API of the things you are used to, relying on autocompletion

See documentation at [https://opensource.respawn.pro/KMPUtils](https://opensource.respawn.pro/KMPUtils)

Javadocs are at [/KMPUtils/javadocs](https://opensource.respawn.pro/KMPUtils/javadocs/)
Javadocs are at [/KMPUtils/javadocs](https://opensource.respawn.pro/KMPUtils/#/javadocs/)

## ‼️ ApiResult has moved! Find the new repository and migration guide at https://github.com/respawn-app/ApiResult ‼️

Expand Down
14 changes: 10 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.dokka)
alias(libs.plugins.dependencyAnalysis)
alias(libs.plugins.atomicfu)
kotlin("plugin.serialization") version libs.versions.kotlin.get() apply false
}

Expand All @@ -28,6 +29,13 @@ allprojects {
version = Config.versionName
}

atomicfu {
dependenciesVersion = rootProject.libs.versions.kotlinx.atomicfu.get()
transformJvm = false
jvmVariant = "VH"
transformJs = false
}

subprojects {
apply(plugin = rootProject.libs.plugins.dokka.id)

Expand Down Expand Up @@ -62,10 +70,8 @@ doctor {
}

dependencyAnalysis {
issues {
all {
ignoreKtx(true)
}
structure {
ignoreKtx(true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Config {
const val artifactId = "$group.$artifact"

const val majorRelease = 1
const val minorRelease = 2
const val minorRelease = 3
const val patch = 0
const val versionName = "$majorRelease.$minorRelease.$patch"

Expand Down
23 changes: 6 additions & 17 deletions buildSrc/src/main/kotlin/ConfigureAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project

fun Project.configureAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
) = commonExtension.apply {
fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
compileSdk = Config.compileSdk

defaultConfig {
minSdk = Config.minSdk
testInstrumentationRunner = Config.testRunner
proguardFiles(getDefaultProguardFile(Config.defaultProguardFile), Config.proguardFile)
}

lint {
warning += "AutoboxingStateCreation"
}

buildTypes {
getByName("release") {
isMinifyEnabled = Config.isMinifyEnabledRelease
Expand All @@ -29,12 +30,6 @@ fun Project.configureAndroid(
targetCompatibility = Config.javaVersion
}

kotlinOptions {
freeCompilerArgs += Config.jvmCompilerArgs
jvmTarget = Config.jvmTarget.target
languageVersion = Config.kotlinVersion.version
}

buildFeatures {
aidl = false
buildConfig = false
Expand All @@ -46,11 +41,6 @@ fun Project.configureAndroid(
compose = false
}

val libs by versionCatalog
composeOptions {
kotlinCompilerExtensionVersion = libs.requireVersion("compose-compiler")
}

packaging {
resources {
excludes += setOf(
Expand All @@ -67,7 +57,6 @@ fun Project.configureAndroid(
isReturnDefaultValues = true
all {
it.apply {
useJUnitPlatform()
maxHeapSize = "1G"
forkEvery = 100
jvmArgs = listOf("-Xmx1g", "-Xms512m")
Expand All @@ -78,7 +67,7 @@ fun Project.configureAndroid(
}

fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
configureAndroid(this)
configureAndroid()

kotlinOptions {
freeCompilerArgs += "-Xexplicit-api=strict"
Expand Down
150 changes: 54 additions & 96 deletions buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
Original file line number Diff line number Diff line change
@@ -1,133 +1,91 @@
@file:Suppress("MissingPackageDeclaration", "unused", "UNUSED_VARIABLE", "UndocumentedPublicFunction", "LongMethod")

import org.gradle.api.Project
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

fun Project.configureMultiplatform(
ext: KotlinMultiplatformExtension,
android: Boolean = false,
ios: Boolean = false,
jvm: Boolean = false,
js: Boolean = false,
linux: Boolean = false,
mingw: Boolean = false,
jvm: Boolean = true,
android: Boolean = true,
linux: Boolean = true,
iOs: Boolean = true,
js: Boolean = true,
tvOs: Boolean = true,
macOs: Boolean = true,
watchOs: Boolean = true
) = ext.apply {
explicitApi()

val libs by versionCatalog
val commonMain by sourceSets.getting
val commonTest by sourceSets.getting {
dependencies {
implementation(kotlin("test"))
}
}
explicitApi()
applyDefaultHierarchyTemplate()
withSourcesJar(true)

sourceSets.apply {
all {
languageSettings {
progressiveMode = true
languageVersion = Config.kotlinVersion.version
progressiveMode = true
Config.optIns.forEach { optIn(it) }
}
}
if (linux) {
linuxX64()
linuxArm64()
mingwX64()
}

if (linux) linuxX64()

if (mingw) mingwX64()

if (js) {
js(IR) {
browser()
nodejs()
binaries.library()
binaries.executable()
}
// TODO: KMM js <> gradle 8.0 incompatibility
tasks.run {
val jsLibrary = named("jsProductionLibraryCompileSync")
val jsExecutable = named("jsProductionExecutableCompileSync")
named("jsBrowserProductionWebpack").configure {
dependsOn(jsLibrary)
}
named("jsBrowserProductionLibraryPrepare").configure {
dependsOn(jsExecutable)
}
named("jsNodeProductionLibraryPrepare").configure {
dependsOn(jsExecutable)
}
}
}

if (android) {
androidTarget {
publishLibraryVariants(Config.publishingVariant)
}

sourceSets.apply {
val androidMain by getting
}
if (android) androidTarget {
publishLibraryVariants("release")
}

if (jvm) {
jvm {
compilations.all {
kotlinOptions {
jvmTarget = Config.jvmTarget.target
freeCompilerArgs += Config.jvmCompilerArgs
}
if (jvm) jvm()

if (iOs) {
sequence {
if (iOs) {
yield(iosX64())
yield(iosArm64())
yield(iosSimulatorArm64())
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
if (macOs) {
yield(macosArm64())
yield(macosX64())
}
}

sourceSets.apply {
val jvmTest by getting {
dependencies {
implementation(libs.requireLib("kotest-junit"))
}
if (tvOs) {
yield(tvosX64())
yield(tvosArm64())
yield(tvosSimulatorArm64())
}
}
}
if (ios) {
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64(),
macosArm64(),
macosX64(),
).forEach {
if (watchOs) {
yield(watchosX64())
yield(watchosArm64())
yield(watchosDeviceArm64())
yield(watchosSimulatorArm64())
}
}.forEach {
it.binaries.framework {
binaryOption("bundleId", Config.artifactId)
binaryOption("bundleVersion", Config.versionName)
baseName = Config.artifactId
}
}
sourceSets.apply {
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}

sourceSets.apply {
if (jvm) {
val jvmTest by getting {
dependencies {
implementation(libs.requireLib("kotest-junit"))
}
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
all {
languageSettings {
progressiveMode = true
languageVersion = Config.kotlinVersion.version
Config.optIns.forEach { optIn(it) }
}
}
} // ios
}
}
5 changes: 2 additions & 3 deletions buildSrc/src/main/kotlin/ConfigurePublication.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@file:Suppress("MissingPackageDeclaration", "unused")

import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import com.android.build.gradle.tasks.BundleAar
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
Expand All @@ -16,7 +15,7 @@ import org.gradle.plugins.signing.Sign
* Configures Maven publishing to sonatype for this project
*/
fun Project.publishMultiplatform() {
val properties = gradleLocalProperties(rootDir)
val properties by localProperties
val isReleaseBuild = properties["release"]?.toString().toBoolean()
val javadocJar = tasks.named("dokkaJavadocJar")

Expand All @@ -42,6 +41,7 @@ fun Project.publishMultiplatform() {
* Publish the android artifact
*/
fun Project.publishAndroid() {
val properties by localProperties
requireNotNull(extensions.findByType<LibraryExtension>()).apply {
publishing {
singleVariant(Config.publishingVariant) {
Expand All @@ -55,7 +55,6 @@ fun Project.publishAndroid() {
}

afterEvaluate {
val properties = gradleLocalProperties(rootDir)
val isReleaseBuild = properties["release"]?.toString().toBoolean()

requireNotNull(extensions.findByType<PublishingExtension>()).apply {
Expand Down
12 changes: 11 additions & 1 deletion buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ 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
import java.util.Properties

/**
* Load version catalog for usage in places where it is not available yet with gradle 7.x.
Expand All @@ -34,7 +37,7 @@ fun VersionCatalog.requireVersion(alias: String) = findVersion(alias).get().toSt

val org.gradle.api.provider.Provider<PluginDependency>.id: String get() = get().pluginId

fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}

Expand All @@ -58,3 +61,10 @@ fun List<String>.toJavaArrayString() = buildString {
}

fun String.toBase64() = Base64.getEncoder().encodeToString(toByteArray())

val Project.localProperties
get() = lazy {
Properties().apply {
load(FileInputStream(File(rootProject.rootDir, "local.properties")))
}
}
10 changes: 1 addition & 9 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@ plugins {
}

kotlin {
configureMultiplatform(
this,
android = false,
ios = true,
jvm = true,
js = true,
linux = true,
mingw = true,
)
configureMultiplatform(this, android = false)
}
Loading

0 comments on commit cf4acd1

Please sign in to comment.