Skip to content

Commit

Permalink
Merge pull request #129 from rafsanjani/develop
Browse files Browse the repository at this point in the history
Optimise maven publication releases
  • Loading branch information
rafsanjani authored Nov 22, 2024
2 parents 2b14db3 + 555cb33 commit e6688f1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Publish to Maven Central

on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id("root.publication")
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.dokka) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ktlint)
signing
}

apply {
Expand Down
2 changes: 2 additions & 0 deletions convention-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ dependencyResolutionManagement {
}
}
}

rootProject.name = "convention-plugins"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ModulePublication : Plugin<Project> {
applyPlugins()
val dokkaOutputDir = layout.buildDirectory.dir("dokka").get().asFile

val deleteDokkaOutputDir = tasks.register<Delete>("deleteDokkaOutputDirectory") {
val deleteDokkaOutputDir by tasks.register<Delete>("deleteDokkaOutputDirectory") {
delete(dokkaOutputDir)
}

Expand All @@ -34,17 +34,9 @@ class ModulePublication : Plugin<Project> {
}

publishing {
// Configure all publications
publications.withType<MavenPublication> {
val mavenPublication = this as? MavenPublication

artifact(javadocJar)

mavenPublication?.artifactId =
"datepickertimeline${
"-$name".takeUnless { "kotlinMultiplatform" in name }.orEmpty()
}".removeSuffix("Release")

pom {
name.set("Datepicker Timeline")
description.set("A linear date picker for jetpack compose multiplatform")
Expand Down Expand Up @@ -82,6 +74,19 @@ class ModulePublication : Plugin<Project> {
tasks.withType(AbstractPublishToMaven::class.java).configureEach {
dependsOn(tasks.withType(Sign::class.java))
}

afterEvaluate {
publishing {
publications.withType<MavenPublication>().configureEach {
artifactId = buildString {
append(project.name)
if (!name.contains("kotlinMultiplatform")) {
append("-$name")
}
}.removeSuffix("Release")
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class RootPublication : Plugin<Project> {
private fun getCurrentBranch(): String {
val command = listOf(
"git",
"rev-parse",
"--abbrev-ref",
"HEAD",
)
val process = ProcessBuilder(command).start()

val output = process.inputStream.bufferedReader().use { it.readText() }
return output
}

private fun getLibraryVersion(): String {
val nextReleaseVersion = "3.0.0"
val currentBranch = getCurrentBranch()

// develop branch is for snapshots whilst main is for releases
return if (currentBranch == "develop") {
"$nextReleaseVersion-SNAPSHOT"
} else {
nextReleaseVersion
}
}

override fun apply(target: Project) {
with(target) {
pluginManager.apply("io.github.gradle-nexus.publish-plugin")

target.allprojects {
allprojects {
group = "io.github.rafsanjani"
version = "1.2.2-SNAPSHOT"
version = getLibraryVersion()
}

nexusPublishing {
Expand All @@ -21,13 +45,8 @@ class RootPublication : Plugin<Project> {
val mavenCentralUsername = System.getenv("MAVEN_CENTRAL_USERNAME")
val mavenCentralPassword = System.getenv("MAVEN_CENTRAL_PASSWORD")

nexusUrl.set(
if (version.toString().endsWith("SNAPSHOT")) {
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
uri("https://s01.oss.sonatype.org/service/local/")
},
)
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))

username.set(mavenCentralUsername)
password.set(mavenCentralPassword)
Expand Down
18 changes: 0 additions & 18 deletions datepickertimeline/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose.multiplatform)
alias(libs.plugins.compose.compiler)
id("org.jetbrains.dokka") version "1.9.20"
`maven-publish`
signing
}

version = "1.0.0"

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
androidTarget()
Expand Down Expand Up @@ -72,17 +67,4 @@ android {
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
}

afterEvaluate {
configure<PublishingExtension> {
publications.all {
val mavenPublication = this as? MavenPublication

mavenPublication?.artifactId =
"datepickertimeline${
"-$name".takeUnless { "kotlinMultiplatform" in name }.orEmpty()
}".removeSuffix("Release")
}
}
}
}

0 comments on commit e6688f1

Please sign in to comment.