Skip to content

Use gradle nexus publish plugin #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PUBLISH_PRODUCTION=
OSSRH_STAGING_PROFILE_ID=
OSSRH_USERNAME=
OSSRH_PASSWORD=
SIGNING_KEYID=
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pull-request-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@ jobs:
with:
distribution: 'adopt'
java-version: '11'
- name: Set env
run: |
echo 'OSSRH_USERNAME=${{ secrets.OSSRH_USERNAME }}' >> $GITHUB_ENV
echo 'OSSRH_PASSWORD=${{ secrets.OSSRH_PASSWORD }}' >> $GITHUB_ENV
echo 'OSSRH_STAGING_PROFILE_ID=${{ secrets.OSSRH_STAGING_PROFILE_ID }}' >> $GITHUB_ENV
echo 'SIGNING_KEYID=${{ secrets.SIGNING_KEYID }}' >> $GITHUB_ENV
echo 'SIGNING_PASSWORD=${{ secrets.SIGNING_PASSWORD }}' >> $GITHUB_ENV
echo 'SIGNING_KEY<<EOF' >> $GITHUB_ENV
echo '${{ secrets.SIGNING_KEY }}' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Gradle clean
run: |
./gradlew clean
- name: Gradle build
run: |
./gradlew build
- name: Gradle publish to mavenLocal
run: |
./gradlew publishToMavenLocal
- name: Gradle publish to nexus-snapshot
run: |
./gradlew publishToSonatype --stacktrace
- name: Upload Build Report
uses: actions/upload-artifact@v1
if: always()
Expand Down
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
plugins {
base
alias(pluginLibs.plugins.dotenv)
alias(pluginLibs.plugins.gradle.nexus.publish)
alias(pluginLibs.plugins.dokka) apply false
alias(pluginLibs.plugins.ktlint)
}
Expand Down Expand Up @@ -38,3 +39,18 @@ subprojects {
ignoreFailures.set(true)
}
}

nexusPublishing {
repositories {
sonatype {
stagingProfileId.set(env.OSSRH_STAGING_PROFILE_ID.orElse(""))
username.set(env.OSSRH_USERNAME.orElse(""))
password.set(env.OSSRH_PASSWORD.orElse(""))
}
}
useStaging.set(!env.PUBLISH_PRODUCTION.isPresent)
transitionCheckOptions {
maxRetries.set(100)
delayBetween.set(java.time.Duration.ofSeconds(5))
}
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencyResolutionManagement {
val assertk = "0.25"
val androidGradlePlugin = "7.0.3" // sdk version is defined in bulidSrc
val dotenv = "1.2.0"
val gradleNexusPublish = "1.1.0"
val ktlint = "10.2.1"

val androidCompileSdkVersion = 31
Expand All @@ -34,6 +35,7 @@ dependencyResolutionManagement {

create("pluginLibs") {
plugin("dotenv", "co.uzzu.dotenv.gradle").version(dotenv)
plugin("gradle-nexus-publish", "io.github.gradle-nexus.publish-plugin").version(gradleNexusPublish)
plugin("kotlin-multiplatform", "org.jetbrains.kotlin.multiplatform").version(kotlin)
plugin("android-library", "com.android.library").version(androidGradlePlugin)
plugin("ktlint", "org.jlleitschuh.gradle.ktlint").version(ktlint)
Expand Down
12 changes: 0 additions & 12 deletions subprojects/core/core.build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ setProperty("archivesBaseName", publishingArtifactIdBase)

afterEvaluate { // workaround for AGP to resolve android library artifactId correctly.
publishing {
repositories {
maven {
url = env.PUBLISH_PRODUCTION.orNull()
?.run { uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") }
?: uri("https://oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = env.OSSRH_USERNAME.orElse("")
password = env.OSSRH_PASSWORD.orElse("")
}
}
}

publications.withType<MavenPublication>().all {
val publishingArtifactId = when (name) {
"metadata" -> {
Expand Down