From 8573ebb835b83f0b6b6ac4be964dccd99e102388 Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Tue, 11 Jul 2023 13:41:16 +0200 Subject: [PATCH] Refactoring to match modern standards --- .github/workflows/deploy.yml | 6 -- .gitignore | 16 +++-- build.gradle.kts | 70 ++----------------- convention-plugins/build.gradle.kts | 8 +-- convention-plugins/settings.gradle.kts | 21 ++++++ ...adle.kts => module.publication.gradle.kts} | 26 +++---- .../main/kotlin/root.publication.gradle.kts | 11 +++ gradle.properties | 18 +++-- gradle/libs.versions.toml | 14 ++++ gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle.kts | 37 ++++++++++ .../androidMain/kotlin/fibiprops.android.kt | 0 .../src}/androidUnitTest/kotlin/FibiTest.kt | 0 .../src}/commonMain/kotlin/CustomFibi.kt | 0 .../src/iosMain/kotlin/fibiprops.ios.kt | 0 .../src/iosTest}/kotlin/FibiTest.kt | 2 +- .../src/jvmMain/kotlin/fibiprops.jvm.kt | 0 .../src}/jvmTest/kotlin/FibiTest.kt | 0 .../linuxX64Main/kotlin/fibiprops.linuxX64.kt | 0 .../src}/linuxX64Test/kotlin/FibiTest.kt | 0 renovate.json | 6 -- settings.gradle.kts | 24 ++++--- src/androidUnitTest/.nop | 0 src/commonTest/.nop | 0 src/iosArm64Test/.nop | 0 src/iosArm64Test/kotlin/FibiTest.kt | 9 --- .../kotlin/firstElement.kt | 2 - src/jvmTest/.nop | 0 src/main/AndroidManifest.xml | 3 - 29 files changed, 137 insertions(+), 138 deletions(-) create mode 100644 convention-plugins/settings.gradle.kts rename convention-plugins/src/main/kotlin/{convention.publication.gradle.kts => module.publication.gradle.kts} (73%) create mode 100644 convention-plugins/src/main/kotlin/root.publication.gradle.kts create mode 100644 gradle/libs.versions.toml create mode 100644 library/build.gradle.kts rename src/androidMain/kotlin/fibiprops.kt => library/src/androidMain/kotlin/fibiprops.android.kt (100%) rename {src => library/src}/androidUnitTest/kotlin/FibiTest.kt (100%) rename {src => library/src}/commonMain/kotlin/CustomFibi.kt (100%) rename src/iosArm64Main/kotlin/fibiprops.kt => library/src/iosMain/kotlin/fibiprops.ios.kt (100%) rename {src/iosSimulatorArm64Test => library/src/iosTest}/kotlin/FibiTest.kt (98%) rename src/jvmMain/kotlin/fibiprops.kt => library/src/jvmMain/kotlin/fibiprops.jvm.kt (100%) rename {src => library/src}/jvmTest/kotlin/FibiTest.kt (100%) rename src/linuxX64Main/kotlin/fibiprops.kt => library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt (100%) rename {src => library/src}/linuxX64Test/kotlin/FibiTest.kt (100%) delete mode 100644 renovate.json delete mode 100644 src/androidUnitTest/.nop delete mode 100644 src/commonTest/.nop delete mode 100644 src/iosArm64Test/.nop delete mode 100644 src/iosArm64Test/kotlin/FibiTest.kt delete mode 100644 src/iosSimulatorArm64Main/kotlin/firstElement.kt delete mode 100644 src/jvmTest/.nop delete mode 100644 src/main/AndroidManifest.xml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a6e8ed..1732689 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,14 +20,8 @@ jobs: strategy: matrix: include: - - target: publishKotlinMultiplatformPublicationToSonatypeRepository - os: macos-latest - target: publishIosArm64PublicationToSonatypeRepository os: macos-latest - - target: publishIosSimulatorArm64PublicationToSonatypeRepository - os: macos-latest - - target: publishAndroidDebugPublicationToSonatypeRepository - os: ubuntu-latest - target: publishAndroidReleasePublicationToSonatypeRepository os: ubuntu-latest - target: publishJvmPublicationToSonatypeRepository diff --git a/.gitignore b/.gitignore index 9538981..e510fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ -/.idea/ -/build/ -/.gradle/ -/convention-plugins/.gradle/ -/convention-plugins/build/ -.envrc +*.iml +.gradle +.idea +.DS_Store +build +captures +.externalNativeBuild +.cxx +local.properties +xcuserdata \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index a698bd3..b9ba347 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,67 +1,7 @@ -import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi - plugins { - kotlin("multiplatform") version "1.9.0" - id("com.android.library") - id("convention.publication") -} - -group = "com.github.asm0dey" -version = "0.0.1.2" - -repositories { - google() - mavenCentral() -} - -@OptIn(ExperimentalKotlinGradlePluginApi::class) -kotlin { - targetHierarchy.default() - jvm { - compilations.all { - kotlinOptions.jvmTarget = "1.8" - } - testRuns["test"].executionTask.configure { - useJUnitPlatform() - } - } - android { - publishLibraryVariants("release", "debug") - } - iosArm64 { - binaries { - framework { - baseName = "library" - } - } - } - iosSimulatorArm64() { - binaries { - framework { - baseName = "library" - } - } - } - linuxX64() - sourceSets { - val commonTest by getting { - dependencies { - implementation(kotlin("test")) - } - } - } -} - -android { - namespace = "com.github.asm0dey.dummylib" - compileSdk = 33 - defaultConfig { - minSdk = 24 - targetSdk = 33 - } - buildTypes { - getByName("release") { - isMinifyEnabled = false - } - } + id("root.publication") + id("module.publication") + //trick: for the same plugin versions in all sub-modules + alias(libs.plugins.androidLibrary).apply(false) + alias(libs.plugins.kotlinMultiplatform).apply(false) } diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts index 8f7d0ae..5e77211 100644 --- a/convention-plugins/build.gradle.kts +++ b/convention-plugins/build.gradle.kts @@ -1,11 +1,7 @@ plugins { - `kotlin-dsl` // Is needed to turn our build logic written in Kotlin into the Gradle Plugin -} - -repositories { - gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin + `kotlin-dsl` } dependencies { - implementation("io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin:2.0.0-rc-1") + implementation(libs.nexus.publish) } \ No newline at end of file diff --git a/convention-plugins/settings.gradle.kts b/convention-plugins/settings.gradle.kts new file mode 100644 index 0000000..ffb42e8 --- /dev/null +++ b/convention-plugins/settings.gradle.kts @@ -0,0 +1,21 @@ +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/module.publication.gradle.kts similarity index 73% rename from convention-plugins/src/main/kotlin/convention.publication.gradle.kts rename to convention-plugins/src/main/kotlin/module.publication.gradle.kts index be922d6..3188f6e 100644 --- a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/module.publication.gradle.kts @@ -1,30 +1,21 @@ import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.`maven-publish` -import org.gradle.kotlin.dsl.signing plugins { `maven-publish` signing - id("io.github.gradle-nexus.publish-plugin") } +group = "com.github.asm0dey.dummylib" +version = "0.0.1" val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } -nexusPublishing { - // Configure maven central repository - repositories { - sonatype() - } - - - // Configure all publications -} - publishing { + // Configure all publications publications.withType { // Stub javadoc.jar artifact artifact(javadocJar.get()) @@ -55,10 +46,9 @@ publishing { } } -val gpgKeyId by extra { System.getenv("secrets.OSSRH_GPG_SECRET_KEY_ID") } -val gpgKey by extra { System.getenv("secrets.OSSRH_GPG_SECRET_KEY") } -val gpgKeyPassword by extra { System.getenv("secrets.OSSRH_GPG_SECRET_KEY_PASSWORD") } signing { - useGpgCmd() - sign(publishing.publications) -} + if (project.hasProperty("signing.gnupg.keyName")) { + useGpgCmd() + sign(publishing.publications) + } +} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts new file mode 100644 index 0000000..b26b067 --- /dev/null +++ b/convention-plugins/src/main/kotlin/root.publication.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +nexusPublishing { + // Configure maven central repository + // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh + repositories { + sonatype() + } +} diff --git a/gradle.properties b/gradle.properties index 75ea504..a56e691 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,14 @@ -kotlin.code.style=official -kotlin.mpp.androidSourceSetLayoutVersion=2 -android.useAndroidX=true -org.gradle.jvmargs=-Xmx4096m -# Improves build time via enabling the gradle build cache +#Gradle +org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" org.gradle.caching=true -org.gradle.configuration-cache=true +#Kotlin +kotlin.code.style=official +kotlin.js.compiler=ir + +#MPP +kotlin.mpp.enableCInteropCommonization=true + +#Android +android.useAndroidX=true +android.nonTransitiveRClass=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..b77d15e --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,14 @@ +[versions] +agp = "8.0.2" +kotlin = "1.9.0" +nexus-publish = "2.0.0-rc-1" +android-minSdk = "24" +android-compileSdk = "33" + +[libraries] +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" } + +[plugins] +androidLibrary = { id = "com.android.library", version.ref = "agp" } +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4e86b92..0c85a1f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/library/build.gradle.kts b/library/build.gradle.kts new file mode 100644 index 0000000..a76ce48 --- /dev/null +++ b/library/build.gradle.kts @@ -0,0 +1,37 @@ +plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidLibrary) + id("module.publication") +} + +kotlin { + targetHierarchy.default() + jvm() + androidTarget { + publishLibraryVariants("release") + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + iosX64() + iosArm64() + iosSimulatorArm64() + linuxX64() + + sourceSets.commonMain.get().dependencies { + //put your multiplatform dependencies here + } + sourceSets.commonTest.get().dependencies { + implementation(libs.kotlin.test) + } +} + +android { + namespace = "com.github.asm0dey.dummylib" + compileSdk = libs.versions.android.compileSdk.get().toInt() + defaultConfig { + minSdk = libs.versions.android.minSdk.get().toInt() + } +} diff --git a/src/androidMain/kotlin/fibiprops.kt b/library/src/androidMain/kotlin/fibiprops.android.kt similarity index 100% rename from src/androidMain/kotlin/fibiprops.kt rename to library/src/androidMain/kotlin/fibiprops.android.kt diff --git a/src/androidUnitTest/kotlin/FibiTest.kt b/library/src/androidUnitTest/kotlin/FibiTest.kt similarity index 100% rename from src/androidUnitTest/kotlin/FibiTest.kt rename to library/src/androidUnitTest/kotlin/FibiTest.kt diff --git a/src/commonMain/kotlin/CustomFibi.kt b/library/src/commonMain/kotlin/CustomFibi.kt similarity index 100% rename from src/commonMain/kotlin/CustomFibi.kt rename to library/src/commonMain/kotlin/CustomFibi.kt diff --git a/src/iosArm64Main/kotlin/fibiprops.kt b/library/src/iosMain/kotlin/fibiprops.ios.kt similarity index 100% rename from src/iosArm64Main/kotlin/fibiprops.kt rename to library/src/iosMain/kotlin/fibiprops.ios.kt diff --git a/src/iosSimulatorArm64Test/kotlin/FibiTest.kt b/library/src/iosTest/kotlin/FibiTest.kt similarity index 98% rename from src/iosSimulatorArm64Test/kotlin/FibiTest.kt rename to library/src/iosTest/kotlin/FibiTest.kt index 3f0ec74..69a1234 100644 --- a/src/iosSimulatorArm64Test/kotlin/FibiTest.kt +++ b/library/src/iosTest/kotlin/FibiTest.kt @@ -6,4 +6,4 @@ class FibiTest { fun `test 3rd element`(){ assertEquals(7, fibi.take(3).last()) } -} +} \ No newline at end of file diff --git a/src/jvmMain/kotlin/fibiprops.kt b/library/src/jvmMain/kotlin/fibiprops.jvm.kt similarity index 100% rename from src/jvmMain/kotlin/fibiprops.kt rename to library/src/jvmMain/kotlin/fibiprops.jvm.kt diff --git a/src/jvmTest/kotlin/FibiTest.kt b/library/src/jvmTest/kotlin/FibiTest.kt similarity index 100% rename from src/jvmTest/kotlin/FibiTest.kt rename to library/src/jvmTest/kotlin/FibiTest.kt diff --git a/src/linuxX64Main/kotlin/fibiprops.kt b/library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt similarity index 100% rename from src/linuxX64Main/kotlin/fibiprops.kt rename to library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt diff --git a/src/linuxX64Test/kotlin/FibiTest.kt b/library/src/linuxX64Test/kotlin/FibiTest.kt similarity index 100% rename from src/linuxX64Test/kotlin/FibiTest.kt rename to library/src/linuxX64Test/kotlin/FibiTest.kt diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 1927fea..0000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 807f0a2..93be8b4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,16 +1,22 @@ pluginManagement { + includeBuild("convention-plugins") repositories { - google() - gradlePluginPortal() - mavenCentral() - } - resolutionStrategy { - eachPlugin { - if (requested.id.namespace == "com.android") { - useModule("com.android.tools.build:gradle:7.4.1") + google { + mavenContent { + releasesOnly() } } + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() } } + rootProject.name = "dummylib-multiplatform" -includeBuild("convention-plugins") +include(":library") diff --git a/src/androidUnitTest/.nop b/src/androidUnitTest/.nop deleted file mode 100644 index e69de29..0000000 diff --git a/src/commonTest/.nop b/src/commonTest/.nop deleted file mode 100644 index e69de29..0000000 diff --git a/src/iosArm64Test/.nop b/src/iosArm64Test/.nop deleted file mode 100644 index e69de29..0000000 diff --git a/src/iosArm64Test/kotlin/FibiTest.kt b/src/iosArm64Test/kotlin/FibiTest.kt deleted file mode 100644 index 2cb6493..0000000 --- a/src/iosArm64Test/kotlin/FibiTest.kt +++ /dev/null @@ -1,9 +0,0 @@ -import kotlin.test.Test -import kotlin.test.assertEquals - -class FibiTest { - @Test - fun `test 3rd element`(){ - assertEquals(8, fibi.take(3).last()) - } -} \ No newline at end of file diff --git a/src/iosSimulatorArm64Main/kotlin/firstElement.kt b/src/iosSimulatorArm64Main/kotlin/firstElement.kt deleted file mode 100644 index 8fb1aa0..0000000 --- a/src/iosSimulatorArm64Main/kotlin/firstElement.kt +++ /dev/null @@ -1,2 +0,0 @@ -actual val firstElement: Int = 3 -actual val secondElement: Int = 4 \ No newline at end of file diff --git a/src/jvmTest/.nop b/src/jvmTest/.nop deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml deleted file mode 100644 index 9a40236..0000000 --- a/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -