Skip to content

Commit

Permalink
Merge pull request #126 from rafsanjani/publish-maven-central
Browse files Browse the repository at this point in the history
Publish maven central
  • Loading branch information
rafsanjani authored Nov 22, 2024
2 parents e271a65 + 16671b5 commit 75750c6
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 49 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish to Maven Central

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

jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
GPG_KEY: ${{ secrets.GPG_KEY }}

steps:
- uses: actions/checkout@v4

- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Configure GPG Key
run: |
mkdir ~/.gpgkey
echo $GPG_KEY > ~/.gpgkey/secring.gpg.b64
base64 -d ~/.gpgkey/secring.gpg.b64 > ~/.gpgkey/secring.gpg
- name: Deploy to Sonatype
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}

run: |
./gradlew publishToSonatype closeAndReleaseStagingRepository --no-parallel --no-daemon -Psigning.keyId=${{secrets.GPG_KEY_ID}} -Psigning.password=${{secrets.GPG_KEY_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gpgkey/secring.gpg)
32 changes: 0 additions & 32 deletions build.gradle

This file was deleted.

25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("root.publication")
alias(libs.plugins.android.library) 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 {
from("scripts/git-hooks.gradle.kts")
}

subprojects {
pluginManager.apply("org.jlleitschuh.gradle.ktlint")
}

ktlint {
version = "1.4.0"
}

group = "io.github.rafsanjani"
22 changes: 22 additions & 0 deletions convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation("io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin:2.0.0")
}

gradlePlugin {
val rootPackageName = "com.foreverrafs.datepickertimeline"

plugins {
register("ModulePublicationConventionPlugin") {
id = "module.publication"
implementationClass = "$rootPackageName.ModulePublication"
}
register("RootPublicationConventionPlugin") {
id = "root.publication"
implementationClass = "$rootPackageName.RootPublication"
}
}
}
21 changes: 21 additions & 0 deletions convention-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}

versionCatalogs {
create("libs") {
from("io.github.rafsanjani:versions:2024.10.27")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.foreverrafs.datepickertimeline

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublicationContainer
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.SigningExtension

class ModulePublication : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
applyPlugins()

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

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

pom {
name.set("Date Picker Timeline")
description.set("A linear date picker for jetpack compose multiplatform")
url.set("https://github.com/rafsanjani/datepickertimeline")

licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/mit")
}
}
issueManagement {
system.set("Github")
url.set("https://github.com/rafsanjani/datepickertimeline/issues")
}
scm {
connection.set("https://github.com/rafsanjani/datepickertimeline.git")
url.set("https://github.com/rafsanjani/datepickertimeline.git")
}
developers {
developer {
id.set("RafsanjaniAziz")
name.set("Rafsanjani Abdul-Aziz")
email.set("[email protected]")
}
}
}
}
}

signing {
sign(publications)
}
}
}
}

private fun Project.applyPlugins() {
pluginManager.apply("signing")
pluginManager.apply("maven-publish")
}

private fun Project.signing(action: SigningExtension.() -> Unit) = extensions.configure(action)
private fun Project.publishing(action: PublishingExtension.() -> Unit) = extensions.configure(action)

private val SigningExtension.publications: PublicationContainer
get() = project.extensions.getByType<PublishingExtension>().publications
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.foreverrafs.datepickertimeline

import io.github.gradlenexus.publishplugin.NexusPublishExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

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

nexusPublishing {
repositories {
sonatype {
val stagingProfileID = System.getenv("OSSRH_STAGING_PROFILE_ID")
val mavenCentralUsername = System.getenv("MAVEN_CENTRAL_USERNAME")
val mavenCentralPassword = System.getenv("MAVEN_CENTRAL_PASSWORD")

useStaging.set(true)

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)
}
}
}
}
}
}

private fun Project.nexusPublishing(action: NexusPublishExtension.() -> Unit) = extensions.configure(action)
25 changes: 25 additions & 0 deletions datepickertimeline/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
@file:Suppress("UnusedPrivateProperty")

plugins {
id("module.publication")
alias(libs.plugins.android.library)
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 @@ -56,8 +62,27 @@ android {
minSdk = libs.versions.minimumSdk.get().toInt()
}

publishing {
singleVariant("release") {
withSourcesJar()
}
}

compileOptions {
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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ class DatePickerState(
restore = {
DatePickerState(
selectedDate = LocalDate(
it[0].toString().toInt(), // year
it[1].toString().toInt(), // month
it[2].toString().toInt(), // day
// year
it[0].toString().toInt(),
// month
it[1].toString().toInt(),
// day
it[2].toString().toInt(),
),
shouldScrollToSelectedDate = it[3]
.toString()
.toBoolean(),
// shouldScrollToSelectedDate
)
},
)
Expand Down
13 changes: 0 additions & 13 deletions scripts/ktlint.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
pluginManagement {
includeBuild("convention-plugins")
repositories {
gradlePluginPortal()
google()
mavenCentral()
mavenLocal()
}
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
gradlePluginPortal()
mavenCentral()
mavenLocal()
}

versionCatalogs {
Expand Down

0 comments on commit 75750c6

Please sign in to comment.