Skip to content

Commit 108e9dd

Browse files
committed
use vanniktech/gradle-maven-publish-plugin to publish, and migrate to maven central portal
1 parent b8dfd0f commit 108e9dd

File tree

8 files changed

+99
-113
lines changed

8 files changed

+99
-113
lines changed

README.md

+35-12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ object Logging {
6060
}
6161
```
6262

63+
## Env Setup
64+
65+
You need install [RVM](https://rvm.io/) to manage your ruby version, and install gems. You need use homebrew to install the following tools:
66+
67+
```bash
68+
brew install cocoapods xcodegen
69+
# if you have installed them earlier, you need remove them at first,
70+
# or run brew link --overwrite xcodegen cocoapods
71+
```
72+
73+
You may need to restart your system so that Android Studio could use the correct ruby.
74+
75+
If you see "pod install" error when you open the project in Android Studio:
76+
77+
```bash
78+
> Task :example:shared:podInstall FAILED
79+
80+
FAILURE: Build failed with an exception.
81+
82+
* What went wrong:
83+
Execution failed for task ':example:shared:podInstall'.
84+
> 'pod install' command failed with code 1.
85+
Error message:
86+
87+
Please, check that podfile contains following lines in header:
88+
source 'https://cdn.cocoapods.org'
89+
90+
Please, check that each target depended on shared contains following dependencies:
91+
```
92+
93+
Please run `./scripts/build_apple.sh` then open/sync again.
94+
6395
## Example
6496

6597
### Android
@@ -82,7 +114,10 @@ pod install
82114

83115
### Linux
84116

117+
Install deps: `zlib1g-dev`.
118+
85119
```bash
120+
./scripts/build_xlog_linux.sh
86121
./gradlew runKmp_xlogDebugExecutableLinuxX64
87122
```
88123

@@ -101,18 +136,6 @@ pod install
101136

102137
## Development
103138

104-
### Env Setup
105-
106-
You need install [RVM](https://rvm.io/) to manage your ruby version, and install gems. You need use homebrew to install the following tools:
107-
108-
```bash
109-
brew install cocoapods xcodegen
110-
# if you have installed them earlier, you need remove them at first,
111-
# or run brew link --overwrite xcodegen cocoapods
112-
```
113-
114-
You may need to restart your system so that Android Studio could use the correct ruby.
115-
116139
### Build MarsXLog
117140

118141
```bash

build.gradle.kts

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ plugins {
1414
alias(libs.plugins.compose.compiler) apply false
1515
alias(libs.plugins.kmp) apply false
1616

17-
alias(libs.plugins.nexus)
17+
alias(libs.plugins.vanniktech.mavenPublish) apply false
18+
1819
alias(libs.plugins.versions)
1920
alias(libs.plugins.versionUpdate)
2021
}
2122

22-
nexusStaging {
23-
packageGroup = Consts.releaseGroup
24-
username = getPropString(project, "ossrhUsername")
25-
password = getPropString(project, "ossrhPassword")
26-
}
27-
2823
versionCatalogUpdate {
2924
sortByKey = false
3025
keep {

buildSrc/src/main/kotlin/convention.publication.gradle.kts

-67
This file was deleted.

example/shared/build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ kotlin {
6161
}
6262
}
6363

64+
applyDefaultHierarchyTemplate()
6465
sourceSets {
6566
commonMain {
6667
dependencies {
@@ -71,17 +72,17 @@ kotlin {
7172

7273
if (isLinux || isWindows) {
7374
cppCommon {
74-
dependsOn(commonMain.get())
75+
dependsOn(commonMain)
7576
}
7677

7778
if (isLinux) {
7879
linuxX64Main {
79-
dependsOn(cppCommon.get())
80+
dependsOn(cppCommon)
8081
}
8182
}
8283
if (isWindows) {
8384
mingwX64Main {
84-
dependsOn(cppCommon.get())
85+
dependsOn(cppCommon)
8586
}
8687
}
8788
}

gradle.properties

-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ android.nonTransitiveRClass=true
1111
#MPP
1212
kotlin.mpp.enableCInteropCommonization=true
1313
kotlin.mpp.androidSourceSetLayoutVersion=2
14-
kotlin.native.binary.memoryModel=experimental
1514
kotlin.js.generate.executable.default=false
16-
17-
#Publish
18-
artifact.name="kmp-xlog"
19-
artifact.desc="KMP wrapper for tencent mars xlog."
20-
artifact.url="https://github.com/HackWebRTC/kmp-xlog"

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ android-application = { id = "com.android.application", version.ref = "agp" }
2828
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
2929
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
3030
kmp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
31-
nexus = "io.codearte.nexus-staging:0.30.0"
3231
versions = "com.github.ben-manes.versions:0.51.0"
3332
versionUpdate = "nl.littlerobots.version-catalog-update:0.8.5"
33+
vanniktech-mavenPublish = "com.vanniktech.maven.publish:0.30.0"

kmp-xlog/build.gradle

+54-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Kotlin DSL only supports syntax shortcut for plugin inside plugins block,
22
// but plugins block doesn't support `if` syntax, so we have to stay on groovy.
3+
import com.vanniktech.maven.publish.SonatypeHost
34

45
plugins {
56
alias libs.plugins.kmp
67

7-
id "convention.publication"
8+
alias libs.plugins.vanniktech.mavenPublish
89
}
910

11+
version = Consts.releaseVersion
12+
group = Consts.releaseGroup
13+
1014
def hostOs = System.getProperty("os.name")
1115
def isMacOS = hostOs == "Mac OS X"
1216
def isWindows = hostOs.startsWith("Windows")
@@ -20,7 +24,7 @@ if (isMacOS) {
2024
kotlin {
2125
if (isMacOS) {
2226
androidTarget() {
23-
publishLibraryVariants("release", "debug")
27+
publishLibraryVariants("release")
2428
}
2529

2630
[iosArm64(), iosSimulatorArm64(), iosX64(), macosArm64(), macosX64()].forEach { t ->
@@ -71,11 +75,13 @@ kotlin {
7175
}
7276
}
7377
}
78+
}
7479

75-
kotlin.freeCompilerArgs += [
76-
"-include-binary",
77-
"${project.projectDir}/src/linuxMain/libs/x64/libkmp_xlog.a".toString()
78-
]
80+
compilerOptions {
81+
freeCompilerArgs.addAll([
82+
"-include-binary",
83+
"${project.projectDir}/src/linuxMain/libs/x64/libkmp_xlog.a".toString()
84+
])
7985
}
8086
}
8187
}
@@ -189,12 +195,13 @@ kotlin {
189195
}
190196
}
191197

198+
applyDefaultHierarchyTemplate()
192199
sourceSets {
193-
if (isMacOS) {
194-
all {
195-
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
196-
}
200+
all {
201+
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
202+
}
197203

204+
if (isMacOS) {
198205
androidUnitTest {
199206
dependencies {
200207
implementation(libs.kotlin.test)
@@ -212,17 +219,17 @@ kotlin {
212219

213220
if (isLinux || isWindows) {
214221
cppCommon {
215-
dependsOn(commonMain.get())
222+
dependsOn(commonMain)
216223
}
217224

218225
if (isLinux) {
219226
linuxX64Main {
220-
dependsOn(cppCommon.get())
227+
dependsOn(cppCommon)
221228
}
222229
}
223230
if (isWindows) {
224231
mingwX64Main {
225-
dependsOn(cppCommon.get())
232+
dependsOn(cppCommon)
226233
}
227234
}
228235
}
@@ -255,3 +262,37 @@ if (isMacOS) {
255262
}
256263
}
257264
}
265+
266+
mavenPublishing {
267+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
268+
269+
signAllPublications()
270+
271+
coordinates(group, Consts.releaseName, version)
272+
273+
pom {
274+
name = "kmp-xlog"
275+
description = "KMP wrapper for tencent mars xlog."
276+
inceptionYear = "2022"
277+
url = "https://github.com/HackWebRTC/kmp-xlog"
278+
licenses {
279+
license {
280+
name = "MIT"
281+
url = "https://opensource.org/licenses/MIT"
282+
distribution = "https://opensource.org/licenses/MIT"
283+
}
284+
}
285+
developers {
286+
developer {
287+
id = "Piasy"
288+
name = "Piasy Xu"
289+
290+
}
291+
}
292+
scm {
293+
url = "https://github.com/HackWebRTC/kmp-xlog"
294+
connection = "scm:git:git://github.com/HackWebRTC/kmp-xlog.git"
295+
developerConnection = "scm:git:git://github.com/HackWebRTC/kmp-xlog.git"
296+
}
297+
}
298+
}

scripts/publish_others.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22

3-
./gradlew publishAllPublicationsToSonatypeRepository closeAndReleaseRepository
3+
./gradlew clean publishAndReleaseToMavenCentral --no-configuration-cache
44

5-
# login to https://s01.oss.sonatype.org/ ,
6-
# find repository in the 'Staging repositories' section,
7-
# close it and release it
5+
# login to https://central.sonatype.com/publishing/deployments ,
6+
# and check the status

0 commit comments

Comments
 (0)