Refactor: Modernize build and publishing workflow

- Upgraded Kotlin from 1.7.20 to 1.9.20.
- Upgraded JDK from 11 to 21 across all GitHub Actions workflows.
- Replaced the legacy `maven-publish` plugin with `com.vanniktech.maven.publish` for simplified publishing to Maven Central.
- Removed the `publishSnapshot.yml` workflow, as snapshot publishing is now managed by the new plugin.
- Updated `publishRelease.yml` to use the `publishToMavenCentral` task and new secrets (`MAVEN_CENTRAL_USERNAME`, `MAVEN_CENTRAL_PASSWORD`).
- Simplified `build.gradle.kts` by removing manual publishing and signing logic.
- Set the JVM target to "21".
- Bumped the project version to `3.1.1`.
- Removed `js` targets and related configurations.
- Added a new code style configuration file for the project (`.idea/codeStyles/Project.xml`).
This commit is contained in:
2025-10-14 12:05:41 +02:00
parent 772eeb0465
commit 6f5ed9c681
5 changed files with 92 additions and 173 deletions

View File

@@ -19,20 +19,18 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 11
distribution: temurin
java-version: '21'
# Runs upload, and then closes & releases the repository
- name: Publish to MavenCentral
run: ./gradlew publish --max-workers 1
run: ./gradlew publishToMavenCentral
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
SNAPSHOT: false

View File

@@ -1,35 +0,0 @@
name: Publish Snapshot
on:
push:
branches: [master]
jobs:
test:
uses: ./.github/workflows/test.yml
secrets: inherit
publish:
needs: test
name: Publish Snapshot
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11
# Runs upload, and then closes & releases the repository
- name: Publish to snapshot to Sonatype
run: ./gradlew publish --max-workers 1
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
SNAPSHOT: true

View File

@@ -12,11 +12,11 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 11
distribution: temurin
java-version: '21'
# Builds the release artifacts of the library
- name: Test

View File

@@ -1,5 +1,40 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<package name="android" withSubpackages="true" static="true" />
<package name="androidx" withSubpackages="true" static="true" />
<package name="com" withSubpackages="true" static="true" />
<package name="junit" withSubpackages="true" static="true" />
<package name="net" withSubpackages="true" static="true" />
<package name="org" withSubpackages="true" static="true" />
<package name="java" withSubpackages="true" static="true" />
<package name="javax" withSubpackages="true" static="true" />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="androidx" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>

View File

@@ -1,147 +1,82 @@
import org.jetbrains.kotlin.konan.properties.Properties
plugins {
kotlin("multiplatform") version "1.7.20"
id("org.jetbrains.dokka") version "1.7.20"
id("maven-publish")
kotlin("multiplatform") version "1.9.20"
id("org.jetbrains.dokka") version "1.9.20"
id("com.vanniktech.maven.publish") version "0.34.0"
signing
}
val PUBLISH_GROUP_ID = "com.github.adriankuta"
val PUBLISH_ARTIFACT_ID = "tree-structure"
val PUBLISH_VERSION = "3.1.0"
val PUBLISH_ARTIFACT_ID = "tree-structure" // base artifact; KMP will add -jvm, -ios*, etc.
val PUBLISH_VERSION = "3.1.1"
val secretFile = File(rootProject.rootDir, "local.properties")
if (secretFile.exists()) {
secretFile.reader().use {
Properties().apply {
load(it)
}
}.onEach { (name, value) ->
project.ext[name.toString()] = value
}
} else {
// Prefer Central Portal credentials via environment variables
project.ext["centralUsername"] = System.getenv("CENTRAL_USERNAME")
project.ext["centralPassword"] = System.getenv("CENTRAL_PASSWORD")
// Fallback legacy OSSRH credentials (still supported on s01)
project.ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
project.ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
project.ext["sonatypeStagingProfileId"] = System.getenv("SONATYPE_STAGING_PROFILE_ID")
project.ext["signingKeyId"] = System.getenv("SIGNING_KEY_ID")
project.ext["signingPassword"] = System.getenv("SIGNING_PASSWORD")
project.ext["signingKey"] = System.getenv("SIGNING_KEY")
project.ext["snapshot"] = System.getenv("SNAPSHOT")
}
val snapshot: String? by project
group = PUBLISH_GROUP_ID
version = if (snapshot.toBoolean()) "$PUBLISH_VERSION-SNAPSHOT" else PUBLISH_VERSION
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
mavenPublishing {
// Central Portal + auto release when we call publishAndReleaseToMavenCentral
publishToMavenCentral(automaticRelease = false)
signAllPublications()
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
coordinates(PUBLISH_GROUP_ID, PUBLISH_ARTIFACT_ID, version.toString())
publishing {
publications {
pom {
name.set("Tree Data Structure")
description.set("Simple implementation to store object in tree structure.")
url.set("https://github.com/AdrianKuta/Tree-Data-Structure")
withType<MavenPublication> {
artifact(javadocJar)
pom {
name.set("Tree Data Structure")
description.set("Simple implementation to store object in tree structure.")
url.set("https://github.com/AdrianKuta/Tree-Data-Structure")
licenses {
license {
name.set("MIT License")
url.set("https://www.mit.edu/~amini/LICENSE.md")
}
}
developers {
developer {
name.set("Adrian Kuta")
email.set("adrian.kuta93@gmail.com")
}
}
scm {
connection.set("scm:git:github.com/AdrianKuta/Tree-Data-Structure.git")
developerConnection.set("scm:git:ssh://github.com/AdrianKuta/Tree-Data-Structure.git")
url.set("https://github.com/AdrianKuta/Tree-Data-Structure/tree/master")
}
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
distribution.set("repo")
}
}
}
repositories {
maven {
name = "SonatypeS01"
// s01 is the supported Nexus host for Central publishing via Maven-compatible uploads
val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
credentials {
// Prefer Central Portal credentials when provided, fallback to legacy OSSRH credentials
val centralUsername: String? by project
val centralPassword: String? by project
val CENTRAL_USERNAME: String? by project
val CENTRAL_PASSWORD: String? by project
val ossrhUsername: String? by project
val ossrhPassword: String? by project
username = centralUsername
?: CENTRAL_USERNAME
?: ossrhUsername
?: System.getenv("CENTRAL_USERNAME")
?: System.getenv("OSSRH_USERNAME")
password = centralPassword
?: CENTRAL_PASSWORD
?: ossrhPassword
?: System.getenv("CENTRAL_PASSWORD")
?: System.getenv("OSSRH_PASSWORD")
developers {
developer {
id.set("AdrianKuta")
name.set("Adrian Kuta")
email.set("adrian.kuta93@gmail.com")
}
}
scm {
url.set("https://github.com/AdrianKuta/Tree-Data-Structure")
connection.set("scm:git:https://github.com/AdrianKuta/Tree-Data-Structure.git")
developerConnection.set("scm:git:ssh://git@github.com/AdrianKuta/Tree-Data-Structure.git")
}
}
}
signing {
val signingKeyId: String? by project
val signingPassword: String? by project
val signingKey: String? by project
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}
// No legacy publishing {} block or s01 repos — Central Portal handles it.
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
kotlin {
jvmToolchain(21);
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(BOTH) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
kotlinOptions {
jvmTarget = "21" // <- was "1.8"
}
}
}
// Add iOS targets
// iOS targets
iosX64()
iosArm64()
iosSimulatorArm64()
// Native host target
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
@@ -153,29 +88,15 @@ kotlin {
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation(kotlin("script-runtime"))
}
}
val commonTest by getting { dependencies { implementation(kotlin("test")) } }
val jvmMain by getting { dependencies { implementation(kotlin("script-runtime")) } }
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
// Shared iOS source sets
val iosMain by creating {
dependsOn(commonMain)
}
val iosTest by creating {
dependsOn(commonTest)
}
val iosMain by creating { dependsOn(commonMain) }
val iosTest by creating { dependsOn(commonTest) }
val iosX64Main by getting { dependsOn(iosMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }