Skip to content

Commit

Permalink
Switch publishing to gradle-maven-publish plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed Jun 6, 2023
1 parent eab3d6e commit 4726496
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 122 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ jobs:
env:
# configureondemand=false to work around KT-51763
GRADLE_OPTS: -Dorg.gradle.configureondemand=false -Dorg.gradle.parallel=true -Dkotlin.incremental=false -Dorg.gradle.project.kotlin.incremental.multiplatform=false -Dorg.gradle.project.kotlin.native.disableCompilerDaemon=true -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_signingKey }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }}
58 changes: 42 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import java.io.ByteArrayOutputStream

@Suppress("DSL_SCOPE_VIOLATION") // https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
kotlin("multiplatform").version(libs.versions.kotlin).apply(false)
alias(libs.plugins.dokka).apply(false)
alias(libs.plugins.publish).apply(false)
}

val VERSION_NAME: String by project

allprojects {
group = "com.github.ajalt.mordant"
version = getPublishVersion()

repositories {
mavenCentral()
}

// Disable npm install scripts
tasks.withType<KotlinNpmInstallTask> {
args += "--ignore-scripts"
}
}

fun getPublishVersion(): String {
// Call gradle with -PinferVersion to set the dynamic version name. Otherwise we skip it to save time.
// Call gradle with -PinferVersion to set the dynamic version name.
// Otherwise, we skip it to save time.
if (!project.hasProperty("inferVersion")) return VERSION_NAME

val stdout = ByteArrayOutputStream()
Expand All @@ -37,3 +28,38 @@ fun getPublishVersion(): String {
val buildNumber = System.getenv("GITHUB_RUN_NUMBER") ?: "0"
return "$VERSION_NAME.$buildNumber-SNAPSHOT"
}



subprojects {
project.setProperty("VERSION_NAME", getPublishVersion())

tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
}

pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")

tasks.named<DokkaTask>("dokkaHtml") {
outputDirectory.set(rootProject.rootDir.resolve("docs/api"))
pluginsMapConfiguration.set(
mapOf(
"org.jetbrains.dokka.base.DokkaBase" to """{
"footerMessage": "Copyright &copy; 2017 AJ Alt"
}"""
)
)
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
}
}
}
}
17 changes: 17 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
VERSION_NAME=2.0.0-beta13

kotlin.mpp.stability.nowarn=true

# gradle-maven-publish configuration
SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
GROUP=com.github.ajalt.mordant
POM_DESCRIPTION=Colorful multiplatform styling Kotlin for command-line applications
POM_INCEPTION_YEAR=2018
POM_URL=https://github.com/ajalt/mordant/
POM_LICENCE_NAME=Apache-2.0
POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0
POM_LICENSE_DIST=repo
POM_SCM_URL=https://github.com/ajalt/
POM_SCM_CONNECTION=scm:git:git://github.com/ajalt/mordant.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/ajalt/mordant.git
POM_DEVELOPER_ID=ajalt
POM_DEVELOPER_NAME=AJ Alt
POM_DEVELOPER_URL=https://github.com/ajalt/
101 changes: 2 additions & 99 deletions mordant/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
@file:Suppress("UNUSED_VARIABLE")
@file:Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress") // https://youtrack.jetbrains.com/issue/KT-38871

import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION") // https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
kotlin("multiplatform")
alias(libs.plugins.dokka)
id("maven-publish")
id("signing")
}


buildscript {
dependencies {
classpath(libs.dokka.base)
}
alias(libs.plugins.publish)
}

kotlin {
Expand Down Expand Up @@ -64,86 +50,3 @@ kotlin {
}
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}

tasks.dokkaHtml.configure {
outputDirectory.set(rootDir.resolve("docs/api"))
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
footerMessage = "Copyright &copy; 2022 AJ Alt"
}
dokkaSourceSets {
configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
}
}
}

val emptyJavadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}


val isSnapshot = version.toString().endsWith("SNAPSHOT")
val signingKey: String? by project
val SONATYPE_USERNAME: String? by project
val SONATYPE_PASSWORD: String? by project

publishing {
publications.withType<MavenPublication>().all {
pom {
description.set("Colorful multiplatform styling Kotlin for command-line applications")
name.set("Mordant")
url.set("https://github.com/ajalt/mordant")
scm {
url.set("https://github.com/ajalt/mordant")
connection.set("scm:git:git://github.com/ajalt/mordant.git")
developerConnection.set("scm:git:ssh://[email protected]/ajalt/mordant.git")
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("ajalt")
name.set("AJ Alt")
url.set("https://github.com/ajalt")
}
}
}
}

repositories {
val releaseUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotUrl = uri("https://oss.sonatype.org/content/repositories/snapshots")
maven {
url = if (isSnapshot) snapshotUrl else releaseUrl
credentials {
username = SONATYPE_USERNAME ?: ""
password = SONATYPE_PASSWORD ?: ""
}
}
}

publications.withType<MavenPublication>().all {
artifact(emptyJavadocJar.get())
}
}

signing {
isRequired = !isSnapshot

if (signingKey != null && !isSnapshot) {
useInMemoryPgpKeys(signingKey, "")
sign(publishing.publications)
}
}
2 changes: 2 additions & 0 deletions mordant/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_ARTIFACT_ID=mordant
POM_NAME=Mordant
11 changes: 7 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ include("samples:table")


dependencyResolutionManagement {
repositories {
mavenCentral()
}
versionCatalogs {
create("libs") {
version("kotlin", "1.8.10")
version("kotlin", "1.8.21")

plugin("dokka", "org.jetbrains.dokka").version("1.7.20")
library("dokka-base", "org.jetbrains.dokka:dokka-base:1.7.20")
plugin("dokka", "org.jetbrains.dokka").version("1.8.10")
plugin("publish", "com.vanniktech.maven.publish").version("0.25.2")

library("colormath", "com.github.ajalt.colormath:colormath:3.2.1")
library("markdown", "org.jetbrains:markdown:0.4.0")
library("markdown", "org.jetbrains:markdown:0.4.1")
library("jna-core", "net.java.dev.jna:jna:5.13.0")

// used in tests
Expand Down

0 comments on commit 4726496

Please sign in to comment.