From 843ac574d0d358a96258b97cbbfd3f82396ef728 Mon Sep 17 00:00:00 2001 From: Nep Date: Fri, 12 Feb 2021 18:57:02 +0900 Subject: [PATCH] publish to Maven Central instead of Bintray --- .github/workflows/maven.yml | 47 ++++++ .gitignore | 5 +- README.md | 35 +--- build.gradle.kts | 316 +++++++++++++++++------------------- gradle.properties | 12 +- settings.gradle.kts | 32 ---- 6 files changed, 202 insertions(+), 245 deletions(-) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..cb67316 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,47 @@ +name: Release + +on: + release: + types: + - published + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Using Caches + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Setup JDK + uses: actions/setup-java@v1.4.3 + with: + java-version: 1.8 + + - name: Grant Execute Permission to gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build + + - name: Build & Release to Maven Central + run: ./gradlew publishToMavenLocal publish closeAndReleaseRepository + env: + VERSION: ${{ github.event.release.tag_name }} + + OSSRH_PROFILE_ID: ${{ secrets.OSSRH_PROFILE_ID }} + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEYID: ${{ secrets.SIGNING_KEYID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + GITHUB_USERNAME: x-access-token + GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 49054cb..b2a4a93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -.gradle/ .idea/ - +.run/ +.gradle/ build/ -out/ diff --git a/README.md b/README.md index e80620b..025e053 100644 --- a/README.md +++ b/README.md @@ -63,43 +63,18 @@ fun main() { } ``` -Get Started ------------ +# Get Started [![GitHub release (latest by date)](https://img.shields.io/github/v/release/StarryBlueSky/Json.kt)](https://github.com/StarryBlueSky/Json.kt/releases) -`build.gradle.kts` - ```kotlin -repositories { - mavenCentral() - jcenter() - - maven(url = "https://dl.bintray.com/starry-blue-sky/stable") - // or dev repository if EAP builds preferred - // maven(url = "https://dl.bintray.com/starry-blue-sky/dev") -} - -kotlin { - sourceSets { - named("commonMain") { - dependencies { - implementation("blue.starry:jsonkt:$jsonkt_version") - } - } - - // Json.kt v6.0+: Not needed anymore - named("jvmMain") { - } - named("jsMain") { - } - } +dependencies { + implementation("blue.starry:jsonkt:$JsonKtVersion") } ``` -License ---------- +# License Json.kt is provided under MIT License. -Copyright (c) 2017-2020 StarryBlueSky. +Copyright (c) 2017-2021 StarryBlueSky. diff --git a/build.gradle.kts b/build.gradle.kts index 4894dd0..81356d5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,87 +1,73 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017-2020 StarryBlueSky - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import com.adarshr.gradle.testlogger.theme.ThemeType -import java.nio.file.Files -import java.nio.file.Paths -import kotlin.collections.set - - -val githubOrganizationName: String = "StarryBlueSky" -val githubRepositoryName: String = "Json.kt" -val packageGroupId: String = "blue.starry" -val packageName: String = "JsonKt" -val packageVersion: Version = Version(6, 0, 0) -val packageDescription: String = "Json bindings for Kotlin" - -object ThirdpartyVersion { - const val KotlinxSerializationRuntime = "1.0.1" - - // for testing - const val JUnit = "5.7.0" - - // for logging - const val KotlinLogging = "2.0.3" - const val Logback = "1.2.3" - const val Jansi = "1.18" -} - plugins { - kotlin("multiplatform") version "1.4.20" + kotlin("multiplatform") version "1.4.30" // For testing + id("org.jlleitschuh.gradle.ktlint") version "10.0.0" id("com.adarshr.test-logger") version "2.1.1" id("net.rdrei.android.buildtimetracker") version "0.11.0" // For publishing `maven-publish` - id("com.jfrog.artifactory") version "4.17.2" + signing + id("io.codearte.nexus-staging") version "0.22.0" // For documentation id("org.jetbrains.dokka") version "1.4.20" } -data class Version(val major: Int, val minor: Int, val patch: Int) { - val label: String - get() = "$major.$minor.$patch" +object Versions { + const val KotlinxSerializationJson = "1.0.1" + + const val JUnit = "5.7.0" + const val KotlinLogging = "2.0.4" + const val Logback = "1.2.3" + const val Jansi = "1.18" +} + +object Libraries { + const val KotlinxSerializationJson = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.KotlinxSerializationJson}" + const val KotlinLogging = "io.github.microutils:kotlin-logging:${Versions.KotlinLogging}" + + const val JUnitJupiter = "org.junit.jupiter:junit-jupiter:${Versions.JUnit}" + const val LogbackCore = "ch.qos.logback:logback-core:${Versions.Logback}" + const val LogbackClassic = "ch.qos.logback:logback-classic:${Versions.Logback}" + const val Jansi = "org.fusesource.jansi:jansi:${Versions.Jansi}" } -// cannot be companion object -val isEAPBuild: Boolean - get() = hasProperty("snapshot") || System.getenv("SNAPSHOT") != null +object Publications { + const val GroupId = "blue.starry" + const val OSSRHProfileGroupId = "blue.starry.jsonkt" + const val Description = "Json bindings for Kotlin" + const val GitHubUsername = "StarryBlueSky" + const val GitHubRepository = "Json.kt" + + const val LicenseName = "The MIT Licence" + const val LicenseUrl = "https://opensource.org/licenses/MIT" + + const val DeveloperId = "StarryBlueSky" + const val DeveloperName = "The Starry Blue Sky" + const val DeveloperEmail = "letter@starry.blue" + const val DeveloperOrganization = "The Starry Blue Sky" + const val DeveloperOrganizationUrl = "https://github.com/StarryBlueSky" + + const val MavenCentralStagingRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" + const val MavenCentralSnapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots" + const val GitHubPackagesRepositoryUrl = "https://maven.pkg.github.com/$GitHubUsername/$GitHubRepository" +} + +object Env { + const val Version = "VERSION" -fun incrementBuildNumber(): Int { - val path = Paths.get(buildDir.absolutePath, "build-number-${packageVersion.label}.txt") - val number = if (Files.exists(path)) { - path.toFile().readText().toIntOrNull() - } else { - null - }?.coerceAtLeast(0)?.plus(1) ?: 1 + const val OSSRHProfileId = "OSSRH_PROFILE_ID" + const val OSSRHUsername = "OSSRH_USERNAME" + const val OSSRHPassword = "OSSRH_PASSWORD" - path.toFile().writeText(number.toString()) + const val GitHubUsername = "GITHUB_USERNAME" + const val GitHubPassword = "GITHUB_PASSWORD" - return number + const val SigningKeyId = "SIGNING_KEYID" + const val SigningKey = "SIGNING_KEY" + const val SigningPassword = "SIGNING_PASSWORD" } /* @@ -90,16 +76,17 @@ fun incrementBuildNumber(): Int { repositories { mavenCentral() + + // TODO: For dokka; should remove it by May 01, 2021 jcenter() } kotlin { - explicitApiWarning() // explicitApi() jvm { compilations.all { - kotlinOptions.jvmTarget = "1.8" + kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() } } js(BOTH) { @@ -116,11 +103,10 @@ kotlin { sourceSets { commonMain { dependencies { - api(kotlin("stdlib")) implementation(kotlin("reflect")) - api("org.jetbrains.kotlinx:kotlinx-serialization-json:${ThirdpartyVersion.KotlinxSerializationRuntime}") - api("io.github.microutils:kotlin-logging:${ThirdpartyVersion.KotlinLogging}") + api(Libraries.KotlinxSerializationJson) + api(Libraries.KotlinLogging) } } commonTest { @@ -136,13 +122,12 @@ kotlin { dependencies { implementation(kotlin("test")) - // For test implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:${ThirdpartyVersion.JUnit}") + implementation(Libraries.JUnitJupiter) - implementation("ch.qos.logback:logback-core:${ThirdpartyVersion.Logback}") - implementation("ch.qos.logback:logback-classic:${ThirdpartyVersion.Logback}") - implementation("org.fusesource.jansi:jansi:${ThirdpartyVersion.Jansi}") + implementation(Libraries.LogbackCore) + implementation(Libraries.LogbackClassic) + implementation(Libraries.Jansi) } } @@ -160,7 +145,7 @@ kotlin { kotlinOptions { apiVersion = "1.4" languageVersion = "1.4" - // allWarningsAsErrors = true + allWarningsAsErrors = true verbose = true } } @@ -171,26 +156,21 @@ kotlin { languageSettings.useExperimentalAnnotation("kotlin.Experimental") languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } - - val publicationsFromMainHost = listOf(jvm(), js()).map { it.name } + "kotlinMultiplatform" - publishing { - publications { - matching { it.name in publicationsFromMainHost }.all { - val targetPublication = this@all - tasks.withType() - .matching { it.publication == targetPublication } - .configureEach { - onlyIf { findProperty("isMainHost") == "true" } - } - } - } - } } /* * Tests */ +ktlint { + verbose.set(true) + outputToConsole.set(true) + reporters { + reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE) + } + ignoreFailures.set(true) +} + buildtimetracker { reporters { register("summary") { @@ -201,14 +181,16 @@ buildtimetracker { } } -testlogger { - theme = ThemeType.MOCHA -} - -tasks.named("jvmTest") { +tasks.withType { useJUnitPlatform() + testLogging { - events("passed", "skipped", "failed") + showStandardStreams = true + events("passed", "failed") + } + + testlogger { + theme = com.adarshr.gradle.testlogger.theme.ThemeType.MOCHA_PARALLEL } } @@ -216,27 +198,7 @@ tasks.named("jvmTest") { * Publishing */ -var buildNumber = incrementBuildNumber() -project.group = packageGroupId -project.version = if (isEAPBuild) { - "${packageVersion.label}-eap-${buildNumber}" -} else { - packageVersion.label -} - tasks { - dokkaHtml { - outputDirectory.set(buildDir.resolve("kdoc")) - - dokkaSourceSets.all { - jdkVersion.set(8) - includeNonPublic.set(false) - reportUndocumented.set(true) - skipEmptyPackages.set(true) - skipDeprecated.set(true) - } - } - register("kdocJar") { from(dokkaHtml) dependsOn(dokkaHtml) @@ -245,80 +207,94 @@ tasks { } publishing { + repositories { + maven { + name = "Sonatype" + url = uri( + if (System.getenv(Env.Version).orEmpty().endsWith("-SNAPSHOT")) { + Publications.MavenCentralSnapshotRepositoryUrl + } else { + Publications.MavenCentralStagingRepositoryUrl + } + ) + + credentials { + username = System.getenv(Env.OSSRHUsername) + password = System.getenv(Env.OSSRHPassword) + } + } + + maven { + name = "GitHubPackages" + url = uri(Publications.GitHubPackagesRepositoryUrl) + + credentials { + username = System.getenv(Env.GitHubUsername) + password = System.getenv(Env.GitHubPassword) + } + } + } + publications.withType { + groupId = Publications.GroupId + artifactId = when (name) { + "kotlinMultiplatform" -> { + rootProject.name + } + else -> { + "${rootProject.name}-$name" + } + } + version = System.getenv(Env.Version) + pom { - name.set(rootProject.name) - description.set(packageDescription) - url.set("https://github.com/$githubOrganizationName/$githubRepositoryName") + name.set(artifactId) + description.set(Publications.Description) + url.set("https://github.com/${Publications.GitHubUsername}/${Publications.GitHubRepository}") licenses { license { - name.set("The MIT Licence") - url.set("https://opensource.org/licenses/MIT") + name.set(Publications.LicenseName) + url.set(Publications.LicenseUrl) } } developers { developer { - name.set("Nep") - email.set("spica@starry.blue") - organization.set("github") - organizationUrl.set("https://github.com/$githubOrganizationName") + id.set(Publications.DeveloperId) + name.set(Publications.DeveloperName) + email.set(Publications.DeveloperEmail) + organization.set(Publications.DeveloperOrganization) + organizationUrl.set(Publications.DeveloperOrganizationUrl) } } scm { - connection.set("scm:git:git://github.com/$githubOrganizationName/$githubRepositoryName.git") - developerConnection.set("scm:git:ssh://github.com:$githubOrganizationName/$githubRepositoryName.git") - url.set("https://github.com/$githubOrganizationName/$githubRepositoryName/tree/master") + url.set("https://github.com/${Publications.GitHubUsername}/${Publications.GitHubRepository}") } } artifact(tasks["kdocJar"]) } +} - val user = System.getenv("BINTRAY_USER") - val key = System.getenv("BINTRAY_KEY") - - if (user != null && key != null) { - repositories { - maven { - name = packageName - description = packageDescription - - val repo = if (isEAPBuild) "dev" else "stable" - url = uri("https://api.bintray.com/maven/starry-blue-sky/$repo/$name/;publish=1;override=1") - - credentials { - username = user - password = key - } - } - } +signing { + setRequired { gradle.taskGraph.hasTask("publish") } + sign(publishing.publications) + + if (System.getenv(Env.SigningKey) != null) { + @Suppress("UnstableApiUsage") + useInMemoryPgpKeys( + System.getenv(Env.SigningKeyId), + System.getenv(Env.SigningKey), + System.getenv(Env.SigningPassword) + ) } } -artifactory { - setContextUrl("http://oss.jfrog.org") - - publish(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "oss-snapshot-local") - setProperty("username", System.getProperty("BINTRAY_USER")) - setProperty("password", System.getProperty("BINTRAY_KEY")) - setProperty("maven", true) - }) - - defaults(delegateClosureOf { - invokeMethod("publications", publishing.publications.names.toTypedArray()) - setProperty("publishArtifacts", true) - setProperty("publishPom", true) - }) - }) - - resolve(delegateClosureOf { - setProperty("repoKey", "jcenter") - }) - - clientConfig.info.buildNumber = buildNumber.toString() +nexusStaging { + packageGroup = Publications.OSSRHProfileGroupId + stagingProfileId = System.getenv(Env.OSSRHProfileId) + username = System.getenv(Env.OSSRHUsername) + password = System.getenv(Env.OSSRHPassword) } diff --git a/gradle.properties b/gradle.properties index 28a21b6..bb29d9b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,9 @@ kotlin.code.style=official -# KT-36076 -#org.gradle.parallel=true -org.gradle.caching=true - kotlin.mpp.stability.nowarn=true + kotlin.mpp.enableGranularSourceSetsMetadata=true -kotlin.mpp.enableCompatibilityMetadataVariant=true -kotlin.native.enableDependencyPropagation=false -kotlin.parallel.tasks.in.project=true -kotlin.incremental.multiplatform=true kotlin.native.ignoreDisabledTargets=true -# Workaround for Bintray treating .sha512 files as artifacts -# https://github.com/gradle/gradle/issues/11412 +# workaround for https://github.com/gradle/gradle/issues/11412 systemProp.org.gradle.internal.publish.checksums.insecure=true diff --git a/settings.gradle.kts b/settings.gradle.kts index 2791c0c..8de8808 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,33 +1 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017-2020 StarryBlueSky - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - rootProject.name = "jsonkt" - -pluginManagement { - repositories { - mavenCentral() - jcenter() - gradlePluginPortal() - } -}