diff --git a/README.md b/README.md index aa303f4..48a7060 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,38 @@ object Logging { } ``` +## Env Setup + +You need install [RVM](https://rvm.io/) to manage your ruby version, and install gems. You need use homebrew to install the following tools: + +```bash +brew install cocoapods xcodegen +# if you have installed them earlier, you need remove them at first, +# or run brew link --overwrite xcodegen cocoapods +``` + +You may need to restart your system so that Android Studio could use the correct ruby. + +If you see "pod install" error when you open the project in Android Studio: + +```bash +> Task :example:shared:podInstall FAILED + +FAILURE: Build failed with an exception. + +* What went wrong: +Execution failed for task ':example:shared:podInstall'. +> 'pod install' command failed with code 1. + Error message: + + Please, check that podfile contains following lines in header: + source 'https://cdn.cocoapods.org' + + Please, check that each target depended on shared contains following dependencies: +``` + +Please run `./scripts/build_apple.sh` then open/sync again. + ## Example ### Android @@ -82,7 +114,10 @@ pod install ### Linux +Install deps: `zlib1g-dev`. + ```bash +./scripts/build_xlog_linux.sh ./gradlew runKmp_xlogDebugExecutableLinuxX64 ``` @@ -101,18 +136,6 @@ pod install ## Development -### Env Setup - -You need install [RVM](https://rvm.io/) to manage your ruby version, and install gems. You need use homebrew to install the following tools: - -```bash -brew install cocoapods xcodegen -# if you have installed them earlier, you need remove them at first, -# or run brew link --overwrite xcodegen cocoapods -``` - -You may need to restart your system so that Android Studio could use the correct ruby. - ### Build MarsXLog ```bash diff --git a/build.gradle.kts b/build.gradle.kts index 5cacee0..18d9152 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,17 +14,12 @@ plugins { alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.kmp) apply false - alias(libs.plugins.nexus) + alias(libs.plugins.vanniktech.mavenPublish) apply false + alias(libs.plugins.versions) alias(libs.plugins.versionUpdate) } -nexusStaging { - packageGroup = Consts.releaseGroup - username = getPropString(project, "ossrhUsername") - password = getPropString(project, "ossrhPassword") -} - versionCatalogUpdate { sortByKey = false keep { diff --git a/buildSrc/src/main/kotlin/convention.publication.gradle.kts b/buildSrc/src/main/kotlin/convention.publication.gradle.kts deleted file mode 100644 index 1f3bf4c..0000000 --- a/buildSrc/src/main/kotlin/convention.publication.gradle.kts +++ /dev/null @@ -1,67 +0,0 @@ -// credit: https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k -import java.util.Properties - -plugins { - `maven-publish` - signing -} - -ext["signing.keyId"] = getPropString(project, "signing.keyId") -ext["signing.password"] = getPropString(project, "signing.password") -ext["signing.secretKeyRingFile"] = getPropString(project, "signing.secretKeyRingFile") - -val javadocJar by tasks.registering(Jar::class) { - archiveClassifier.set("javadoc") -} - -publishing { - // Configure maven central repository - repositories { - maven { - name = "sonatype" - setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = getPropString(project, "ossrhUsername") - password = getPropString(project, "ossrhPassword") - } - } - } - - // Configure all publications - publications.withType { - // Stub javadoc.jar artifact - artifact(javadocJar.get()) - - // Provide artifacts information requited by Maven Central - pom { - name.set(project.name) - description.set(getPropString(project, "artifact.desc")) - url.set(getPropString(project, "artifact.url")) - - licenses { - license { - name.set("MIT") - url.set("https://opensource.org/licenses/MIT") - } - } - developers { - developer { - id.set("Piasy") - name.set("Piasy Xu") - email.set("xz4215@gmail.com") - } - } - scm { - url.set(getPropString(project, "artifact.url")) - } - } - } -} - -// Signing artifacts. Signing.* extra properties values will be used -signing { - sign(publishing.publications) -} - -group = Consts.releaseGroup -version = Consts.releaseVersion diff --git a/example/shared/build.gradle b/example/shared/build.gradle index 87506c0..e66af05 100644 --- a/example/shared/build.gradle +++ b/example/shared/build.gradle @@ -61,6 +61,7 @@ kotlin { } } + applyDefaultHierarchyTemplate() sourceSets { commonMain { dependencies { @@ -71,17 +72,17 @@ kotlin { if (isLinux || isWindows) { cppCommon { - dependsOn(commonMain.get()) + dependsOn(commonMain) } if (isLinux) { linuxX64Main { - dependsOn(cppCommon.get()) + dependsOn(cppCommon) } } if (isWindows) { mingwX64Main { - dependsOn(cppCommon.get()) + dependsOn(cppCommon) } } } diff --git a/gradle.properties b/gradle.properties index 14572fd..4dabc08 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,10 +11,4 @@ android.nonTransitiveRClass=true #MPP kotlin.mpp.enableCInteropCommonization=true kotlin.mpp.androidSourceSetLayoutVersion=2 -kotlin.native.binary.memoryModel=experimental kotlin.js.generate.executable.default=false - -#Publish -artifact.name="kmp-xlog" -artifact.desc="KMP wrapper for tencent mars xlog." -artifact.url="https://github.com/HackWebRTC/kmp-xlog" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 46b4c7c..f47172d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,6 +28,6 @@ android-application = { id = "com.android.application", version.ref = "agp" } kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kmp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -nexus = "io.codearte.nexus-staging:0.30.0" versions = "com.github.ben-manes.versions:0.51.0" versionUpdate = "nl.littlerobots.version-catalog-update:0.8.5" +vanniktech-mavenPublish = "com.vanniktech.maven.publish:0.30.0" diff --git a/kmp-xlog/build.gradle b/kmp-xlog/build.gradle index 1058a14..2d160be 100644 --- a/kmp-xlog/build.gradle +++ b/kmp-xlog/build.gradle @@ -1,12 +1,16 @@ // Kotlin DSL only supports syntax shortcut for plugin inside plugins block, // but plugins block doesn't support `if` syntax, so we have to stay on groovy. +import com.vanniktech.maven.publish.SonatypeHost plugins { alias libs.plugins.kmp - id "convention.publication" + alias libs.plugins.vanniktech.mavenPublish } +version = Consts.releaseVersion +group = Consts.releaseGroup + def hostOs = System.getProperty("os.name") def isMacOS = hostOs == "Mac OS X" def isWindows = hostOs.startsWith("Windows") @@ -20,7 +24,7 @@ if (isMacOS) { kotlin { if (isMacOS) { androidTarget() { - publishLibraryVariants("release", "debug") + publishLibraryVariants("release") } [iosArm64(), iosSimulatorArm64(), iosX64(), macosArm64(), macosX64()].forEach { t -> @@ -71,11 +75,13 @@ kotlin { } } } + } - kotlin.freeCompilerArgs += [ - "-include-binary", - "${project.projectDir}/src/linuxMain/libs/x64/libkmp_xlog.a".toString() - ] + compilerOptions { + freeCompilerArgs.addAll([ + "-include-binary", + "${project.projectDir}/src/linuxMain/libs/x64/libkmp_xlog.a".toString() + ]) } } } @@ -189,12 +195,13 @@ kotlin { } } + applyDefaultHierarchyTemplate() sourceSets { - if (isMacOS) { - all { - languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi") - } + all { + languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi") + } + if (isMacOS) { androidUnitTest { dependencies { implementation(libs.kotlin.test) @@ -212,17 +219,17 @@ kotlin { if (isLinux || isWindows) { cppCommon { - dependsOn(commonMain.get()) + dependsOn(commonMain) } if (isLinux) { linuxX64Main { - dependsOn(cppCommon.get()) + dependsOn(cppCommon) } } if (isWindows) { mingwX64Main { - dependsOn(cppCommon.get()) + dependsOn(cppCommon) } } } @@ -255,3 +262,37 @@ if (isMacOS) { } } } + +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + signAllPublications() + + coordinates(group, Consts.releaseName, version) + + pom { + name = "kmp-xlog" + description = "KMP wrapper for tencent mars xlog." + inceptionYear = "2022" + url = "https://github.com/HackWebRTC/kmp-xlog" + licenses { + license { + name = "MIT" + url = "https://opensource.org/licenses/MIT" + distribution = "https://opensource.org/licenses/MIT" + } + } + developers { + developer { + id = "Piasy" + name = "Piasy Xu" + url = "xz4215@gmail.com" + } + } + scm { + url = "https://github.com/HackWebRTC/kmp-xlog" + connection = "scm:git:git://github.com/HackWebRTC/kmp-xlog.git" + developerConnection = "scm:git:git://github.com/HackWebRTC/kmp-xlog.git" + } + } +} diff --git a/scripts/publish_others.sh b/scripts/publish_others.sh index f0a9207..a104b2e 100755 --- a/scripts/publish_others.sh +++ b/scripts/publish_others.sh @@ -1,7 +1,6 @@ #!/bin/bash -./gradlew publishAllPublicationsToSonatypeRepository closeAndReleaseRepository +./gradlew clean publishAndReleaseToMavenCentral --no-configuration-cache -# login to https://s01.oss.sonatype.org/ , -# find repository in the 'Staging repositories' section, -# close it and release it +# login to https://central.sonatype.com/publishing/deployments , +# and check the status