Skip to content

Commit

Permalink
use vanniktech/gradle-maven-publish-plugin to publish, and migrate to…
Browse files Browse the repository at this point in the history
… maven central portal
  • Loading branch information
Piasy committed Dec 11, 2024
1 parent b8dfd0f commit 108e9dd
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 113 deletions.
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +114,10 @@ pod install

### Linux

Install deps: `zlib1g-dev`.

```bash
./scripts/build_xlog_linux.sh
./gradlew runKmp_xlogDebugExecutableLinuxX64
```

Expand All @@ -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
Expand Down
9 changes: 2 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
67 changes: 0 additions & 67 deletions buildSrc/src/main/kotlin/convention.publication.gradle.kts

This file was deleted.

7 changes: 4 additions & 3 deletions example/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ kotlin {
}
}

applyDefaultHierarchyTemplate()
sourceSets {
commonMain {
dependencies {
Expand All @@ -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)
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
67 changes: 54 additions & 13 deletions kmp-xlog/build.gradle
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -20,7 +24,7 @@ if (isMacOS) {
kotlin {
if (isMacOS) {
androidTarget() {
publishLibraryVariants("release", "debug")
publishLibraryVariants("release")
}

[iosArm64(), iosSimulatorArm64(), iosX64(), macosArm64(), macosX64()].forEach { t ->
Expand Down Expand Up @@ -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()
])
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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 = "[email protected]"
}
}
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"
}
}
}
7 changes: 3 additions & 4 deletions scripts/publish_others.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 108e9dd

Please sign in to comment.