Skip to content

Commit

Permalink
feat: migrate to simple-kmm gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmonDantes committed Jun 12, 2023
1 parent 7f2a52d commit 62f6834
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 301 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/check.yml
Expand Up @@ -2,8 +2,10 @@ name: check

on:
push:
branches-ignore:
'release/**'
branches:
- '*'
tags-ignore:
- '*'

jobs:
build:
Expand All @@ -20,4 +22,4 @@ jobs:
- name: Fetch origin/master
run: git fetch origin master
- name: Build
run: ./gradlew clean build --no-daemon --no-parallel --stacktrace
run: ./gradlew -Psimple.kmm.spotless.ratchet.git.branch=origin/master clean build --no-daemon --no-parallel --stacktrace
53 changes: 0 additions & 53 deletions .github/workflows/maven_publish.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/sonatypePublish.yml
@@ -0,0 +1,57 @@
name: publish to sonatype

on:
push:
tags:
- 'v*'
jobs:
generate_publish_id:
runs-on: ubuntu-latest
name: Create staging repository
outputs:
repository_id: ${{ steps.create.outputs.repository_id }}
steps:
- id: create
uses: nexus-actions/create-nexus-staging-repo@3e5e7209801629febdcf75541a4898710d28df9a
with:
username: ${{ secrets.PUBLISH_REPOSITORY_USERNAME }}
password: ${{ secrets.PUBLISH_REPOSITORY_PASSWORD }}
staging_profile_id: ${{ secrets.SONATYPE_PROFILE_ID }}
base_url: ${{ secrets.SONATYPE_BASE_URL }}
publish:
needs: generate_publish_id
strategy:
matrix:
include:
- os: macos-latest
gradlew: gradlew
- os: ubuntu-latest
gradlew: gradlew
env: all
runs-on: ${{ matrix.os }}
steps:
- name: Print publishing type
run: echo "This runner with env type = ${{ matrix.env == 'all' && 'all' || 'native' }}"
- name: Checkout
uses: actions/checkout@v3
- name: Configure JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '11'
- name: Fetch origin/master
run: git fetch origin master
- name: Publish
run: |
./${{ matrix.gradlew }} \
-Psimple.kmm.spotless.ratchet.git.branch=origin/master \
-Psimple.kmm.publish.repository.url="${{ secrets.PUBLISH_REPOSITORY_URL }}" \
-Psimple.kmm.publish.repository.id="${{ needs.generate_publish_id.outputs.repository_id }}" \
-Psimple.kmm.publish.username="${{ secrets.PUBLISH_REPOSITORY_USERNAME }}" \
-Psimple.kmm.publish.password="${{ secrets.PUBLISH_REPOSITORY_PASSWORD }}" \
-Psimple.kmm.sign.key.id="${{ secrets.SIGNING_KEY_ID }}" \
-Psimple.kmm.sign.password="${{ secrets.SIGNING_PASSWORD }}" \
-Psimple.kmm.sign.private.key="${{ secrets.SIGNING_PRIVATE_KEY }}" \
-Psimple.kmm.kotlin.compile.only.platform="${{ matrix.env == 'all' && 'false' || 'true' }}" \
-Psimple.kmm.kotlin.compile.browser.enabled=false \
clean publish --no-daemon --no-parallel --stacktrace
File renamed without changes.
233 changes: 23 additions & 210 deletions build.gradle.kts
@@ -1,4 +1,4 @@
import org.jetbrains.kotlin.cli.common.toBooleanLenient
import io.github.edmondantes.simple.kotlin.multiplatform.gradle.plugin.util.property.gradleProperty

/*
* Copyright (c) 2023. Ilia Loginov
Expand All @@ -14,113 +14,14 @@ import org.jetbrains.kotlin.cli.common.toBooleanLenient
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
signing
`maven-publish`
kotlin("multiplatform")
kotlin("plugin.serialization")
id("org.jetbrains.dokka") version "1.8.10"
id("com.diffplug.spotless") version "6.18.0"
id("org.jetbrains.kotlinx.kover") version "0.6.1"
id("com.palantir.git-version") version "3.0.0"
}

val gitVersion: groovy.lang.Closure<String> by extra

group = "io.github.edmondantes"
version = gitVersion(mapOf("prefix" to "v@"))

java.targetCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
maven {
name = "Sonatype_releases"
url = uri("https://s01.oss.sonatype.org/content/repositories/releases/")
}
maven {
name = "Sonatype_snapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}

spotless {
if (file("./.git").exists()) {
val defaultBranch = project.extra.properties["git.default.branch"] ?: "master"
ratchetFrom("origin/${defaultBranch}")
}
encoding("UTF-8")

kotlin {
target("src/*/kotlin/**/*.kt")
ktlint("0.48.2")
licenseHeaderFile("LICENSE_FILE_HEADER")
}
}

val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)

val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
id("io.github.edmondantes.simple.kmm.gradle.plugin")
}

val isMainHost: Boolean = extra["publication.only.platform"]?.toString()?.toBooleanStrictOrNull() != true

kotlin {
explicitApi()
if (isMainHost) {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
val hasBrowser: Boolean = extra["kotlin.js.browser.enable"]?.toString()?.toBooleanLenient() == true
if (hasBrowser) {
browser {
commonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
}
}
nodejs()
}
}

val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
when {
hostOs == "Mac OS X" -> {
macosX64("macosX64")
iosArm64("iosArm64")
iosX64("iosX64")
}

hostOs == "Linux" -> {
linuxX64("linuxX64")
linuxArm64("linuxArm64")
}

isMingwX64 -> {
mingwX64()
}

else -> throw GradleException("Host OS is not supported for this project")
}

val kotlinSerializationVersion: String = extra["kotlin.serialization.version"]?.toString()
?: error("Can not get 'kotlin.serialization.version'")

sourceSets {
val kotlinSerializationVersion: String by gradleProperty { }

val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinSerializationVersion")
Expand All @@ -134,117 +35,29 @@ kotlin {
}
}

signing {
val keyId = findProperty("signingKeyId") as String?
val privateKey = findProperty("signingPrivateKey") as String?
val password = findProperty("signingPassword") as String?
if (!keyId.isNullOrBlank() && !privateKey.isNullOrBlank() && !password.isNullOrBlank()) {
useInMemoryPgpKeys(keyId, privateKey, password)
sign(publishing.publications)
}
}

// Added because it is issue: https://youtrack.jetbrains.com/issue/KT-46466
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(signingTasks)
licenses {
apache2()
}

publishing {
publications {
withType<MavenPublication>().all {
if (name == "kotlinMultiplatform") {
tasks.withType<AbstractPublishToMaven>()
.matching { it.publication == this }
.configureEach { onlyIf("If it is main host for all mainly publications") { isMainHost } }
}

groupId = project.group.toString()
version = project.version.toString()

with(pom) {
name.set("Simple kotlinx serialization utils")
description.set("Small library which provide some utilities for koltinx.serialization")
url.set("https://github.com/EdmonDantes/${project.name}")
developers {
developer {
name.set("Ilia Loginov")
email.set("masaqaz40@gmail.com")
organization.set("github")
organizationUrl.set("https://www.github.com")
}
}
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
connection.set("scm:git:git://github.com/EdmonDantes/${project.name}.git")
developerConnection.set("scm:git:ssh://github.com:EdmonDantes/${project.name}.git")
url.set("https://github.com/EdmonDantes/${project.name}/tree/master")
}
}

artifact(javadocJar)
}
}

repositories {
maven {
val publishRepositoryId: String? by project
val publishRepositoryUrl: String? by project

val resultUrl =
if (publishRepositoryUrl.isNullOrBlank() || publishRepositoryId.isNullOrBlank()) {
publishRepositoryUrl.orEmpty().ifEmpty { "./build/repo/" }
} else {
var resolvedUrl = publishRepositoryUrl.orEmpty().ifEmpty { "./build/repo/" }
if (!resolvedUrl.endsWith('/') && !publishRepositoryId!!.startsWith('/')) {
resolvedUrl += '/'
}

resolvedUrl + publishRepositoryId
}

url = uri(resultUrl)

val username = project.findProperty("sonatypeUsername") as String?
val password = project.findProperty("sonatypePassword") as String?
if (!username.isNullOrEmpty() && !password.isNullOrEmpty()) {
credentials {
this.username = username
this.password = password
}
}
}
}
}

tasks.withType<Delete> {
delete += listOf("$projectDir/kotlin-js-store")
}

tasks.register("enableTestLogging") {
group = "testEnv"
doLast {
val envFile = file("src/commonTest/kotlin/env/Env.kt")
val text = envFile.readText()
envFile.writeText(text.replace(Regex(".*isEnableLogging.*"), " val isEnableLogging: Boolean = true"))
developers {
developer {
name = "Ilia Loginov"
email = "masaqaz40@gmail.com"
organizationName("github")
role("Maintainer")
role("Developer")
}
}

tasks.register("disableTestLogging") {
group = "testEnv"
doLast {
val envFile = file("src/commonTest/kotlin/env/Env.kt")
val text = envFile.readText()
envFile.writeText(text.replace(Regex(".*isEnableLogging.*"), " val isEnableLogging: Boolean = false"))
simplePom {
any {
title = "Simple kotlinx serialization utils"
description = "Small library which provide some utilities for koltinx.serialization"
url = "#github::Simple-Kotlin-Project::${project.name}"
scm {
url = "#github::Simple-Kotlin-Project::${project.name}::master"
connection = "#github::Simple-Kotlin-Project::${project.name}"
developerConnection = "#github::Simple-Kotlin-Project::${project.name}"
}
}
}

tasks.withType<Test> {
dependsOn("disableTestLogging")
finalizedBy("enableTestLogging")
}

0 comments on commit 62f6834

Please sign in to comment.