Skip to content

Commit

Permalink
Merge pull request #17 from skydoves/migrate/maven-publish
Browse files Browse the repository at this point in the history
Migrate maven publicaion scripts & plugin
  • Loading branch information
skydoves authored Oct 8, 2023
2 parents 8ca07db + f36d644 commit 89c2325
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 180 deletions.
32 changes: 18 additions & 14 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
uses: actions/checkout@v3.1.0

- name: Set up JDK 17
uses: actions/setup-java@v3.5.1
with:
distribution: adopt
java-version: 11
distribution: 'zulu'
java-version: 17

- name: Grant Permission to Execute Gradle
run: chmod +x gradlew

- name: Release build
run: ./gradlew assemble --scan
- name: Source jar and dokka
run: ./gradlew androidSourcesJar javadocJar --scan

- name: Publish to MavenCentral
run: ./gradlew publishReleasePublicationToSonatypeRepository --scan
run: |
./gradlew publishAllPublicationsToMavenCentral --no-daemon --no-parallel
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
SNAPSHOT: true
37 changes: 21 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@ name: Publish

on:
release:
types: [released]
types: [ released ]
workflow_dispatch:

jobs:
publish:
name: Release build and publish
name: Snapshot build and publish
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
uses: actions/checkout@v3.1.0

- name: Set up JDK 17
uses: actions/setup-java@v3.5.1
with:
distribution: adopt
java-version: 11
distribution: 'zulu'
java-version: 17

- name: Grant Permission to Execute Gradle
run: chmod +x gradlew

- name: Release build
run: ./gradlew assemble --scan
- name: Source jar and dokka
run: ./gradlew androidSourcesJar javadocJar --scan

- name: Publish to MavenCentral
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository --scan
run: |
./gradlew publishAllPublicationsToMavenCentral --no-configuration-cache
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ plugins {
alias(libs.plugins.dokka)
}

apply(from ="${rootDir}/scripts/publish-root.gradle")

subprojects {
if (name != "app") {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
Expand Down
27 changes: 26 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,29 @@ android.defaults.buildfeatures.shaders=false
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
# https://developer.android.com/studio/releases/gradle-plugin#4.1-nontransitive-r-class
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true

# Required to publish to Nexus (see https://github.com/gradle/gradle/issues/11308)
systemProp.org.gradle.internal.publish.checksums.insecure=true

# Increase timeout when pushing to Sonatype (otherwise we get timeouts)
systemProp.org.gradle.internal.http.socketTimeout=120000


POM_URL=https://github.com/skydoves/whatif/
POM_SCM_URL=https://github.com/skydoves/whatif/
POM_SCM_CONNECTION=scm:git:git://github.com/skydoves/whatif.git
POM_SCM_DEV_CONNECTION=scm:git:git://github.com/skydoves/whatif.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=skydoves
POM_DEVELOPER_NAME=Jaewoong Eum
POM_DEVELOPER_URL=https://github.com/skydoves/
POM_DEVELOPER_EMAIL=skydoves2@gmail.com

SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
SONATYPE_AUTOMATIC_RELEASE=true
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
agp = "8.1.2"
kotlin = "1.9.10"
dokka = "1.9.0"
nexusPlugin = "1.3.0"
nexusPlugin = "0.25.3"
kotlinBinaryCompatibility = "0.13.1"
jvmTarget = "1.8"
material = "1.10.0"
Expand All @@ -22,7 +22,7 @@ android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
nexus-plugin = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPlugin" }
nexus-plugin = { id = "com.vanniktech.maven.publish", version.ref = "nexusPlugin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
kotlin-binary-compatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompatibility" }

Expand Down
87 changes: 0 additions & 87 deletions scripts/publish-module.gradle

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/publish-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

apply(plugin = "com.vanniktech.maven.publish")

rootProject.extra.apply {
val snapshot = System.getenv("SNAPSHOT").toBoolean()
val libVersion = if (snapshot) {
Configuration.snapshotVersionName
} else {
Configuration.versionName
}
set("libVersion", libVersion)
}
46 changes: 0 additions & 46 deletions scripts/publish-root.gradle

This file was deleted.

21 changes: 15 additions & 6 deletions whatif-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ plugins {
id(libs.plugins.android.library.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.binary.compatibility.get().pluginId)
id(libs.plugins.nexus.plugin.get().pluginId)
}

rootProject.extra.apply {
set("PUBLISH_GROUP_ID", Configuration.artifactGroup)
set("PUBLISH_ARTIFACT_ID", "whatif-android")
set("PUBLISH_VERSION", rootProject.extra.get("rootVersionName"))
}
apply(from = "${rootDir}/scripts/publish-module.gradle.kts")

mavenPublishing {
val artifactId = "whatif-android"
coordinates(
Configuration.artifactGroup,
artifactId,
rootProject.extra.get("libVersion").toString()
)

apply(from ="${rootDir}/scripts/publish-module.gradle")
pom {
name.set(artifactId)
description.set("Fluent syntactic sugar of Kotlin for handling single if-else statements, nullable, collections, and booleans.")
}
}

android {
namespace = "com.skydoves.whatif.android"
Expand Down
20 changes: 14 additions & 6 deletions whatif/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
plugins {
kotlin("jvm")
id(libs.plugins.nexus.plugin.get().pluginId)
id(libs.plugins.kotlin.binary.compatibility.get().pluginId)
}

rootProject.extra.apply {
set("PUBLISH_GROUP_ID", Configuration.artifactGroup)
set("PUBLISH_ARTIFACT_ID", "whatif")
set("PUBLISH_VERSION", rootProject.extra.get("rootVersionName"))
}
apply(from = "${rootDir}/scripts/publish-module.gradle.kts")

apply(from ="${rootDir}/scripts/publish-module.gradle")
mavenPublishing {
val artifactId = "whatif"
coordinates(
Configuration.artifactGroup,
artifactId,
rootProject.extra.get("libVersion").toString()
)

pom {
name.set(artifactId)
description.set("Fluent syntactic sugar of Kotlin for handling single if-else statements, nullable, collections, and booleans.")
}
}

dependencies {
testImplementation(libs.junit)
Expand Down

0 comments on commit 89c2325

Please sign in to comment.