-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5213c5
commit e85070f
Showing
3 changed files
with
145 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: publish | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: "publish" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
publish: | ||
environment: MavenRelease | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: temurin | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Publish | ||
uses: gradle/gradle-build-action@v2 | ||
env: | ||
ORG_GRADLE_PROJECT_ossrhUser: ${{ secrets.OSSRH_USER }} | ||
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }} | ||
ORG_GRADLE_PROJECT_stagingProfile: ${{ secrets.STAGING_PROFILE_ID }} | ||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_KEY }} | ||
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.GPG_KEYID }} | ||
with: | ||
arguments: "publishToSonatype closeAndReleaseStagingRepository" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,10 @@ buildscript { | |
|
||
plugins { | ||
`maven-publish` | ||
signing | ||
|
||
kotlin("jvm") version "1.+" | ||
id("io.github.gradle-nexus.publish-plugin") version "1.+" | ||
id("io.gitlab.arturbosch.detekt") version "1.+" | ||
id("org.jetbrains.dokka") version "1.+" | ||
} | ||
|
@@ -95,7 +98,6 @@ dependencies { | |
|
||
|
||
|
||
|
||
//////////////////////// | ||
// Task Configuration // | ||
//////////////////////// | ||
|
@@ -124,35 +126,6 @@ tasks { | |
|
||
|
||
|
||
//////////////// | ||
// Publishing // | ||
//////////////// | ||
|
||
publishing.publications { | ||
register<MavenPublication>("Release") { | ||
from(components["java"]) | ||
groupId = project.group as String | ||
artifactId = project.name | ||
version = project.version as String | ||
|
||
artifact(javadocJar) | ||
artifact(sourcesJar) | ||
|
||
// Uses the resolved version instead of the 1.+ wildcards | ||
// See https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:resolved_dependencies | ||
versionMapping { | ||
usage("java-api") { | ||
fromResolutionOf("runtimeClasspath") | ||
} | ||
usage("java-runtime") { | ||
fromResolutionResult() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
///////////// | ||
// Linting // | ||
///////////// | ||
|
@@ -193,3 +166,111 @@ tasks.getByName("dokkaHtml", DokkaTask::class) { | |
} | ||
} | ||
} | ||
|
||
|
||
|
||
//////////////// | ||
// Publishing // | ||
//////////////// | ||
|
||
|
||
fun getProjectProperty(name: String) = project.properties[name] as? String | ||
|
||
|
||
// Generate pom file for maven central | ||
|
||
fun generatePom(): MavenPom.() -> Unit { | ||
return { | ||
packaging = "jar" | ||
name.set(project.name) | ||
description.set("Collection of useful Kotlin extensions for JDA") | ||
url.set("https://github.com/MinnDevelopment/jda-ktx") | ||
scm { | ||
url.set("https://github.com/MinnDevelopment/jda-ktx") | ||
connection.set("scm:git:git://github.com/MinnDevelopment/jda-ktx") | ||
developerConnection.set("scm:git:ssh:[email protected]:MinnDevelopment/jda-ktx") | ||
} | ||
licenses { | ||
license { | ||
name.set("The Apache Software License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
distribution.set("repo") | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set("Minn") | ||
name.set("Florian Spieß") | ||
email.set("[email protected]") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
publishing.publications { | ||
register<MavenPublication>("Release") { | ||
from(components["java"]) | ||
artifactId = project.name | ||
groupId = project.group as String | ||
version = project.version as String | ||
|
||
artifact(javadocJar) | ||
artifact(sourcesJar) | ||
|
||
pom.apply(generatePom()) | ||
|
||
// Uses the resolved version instead of the 1.+ wildcards | ||
// See https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:resolved_dependencies | ||
versionMapping { | ||
usage("java-api") { | ||
fromResolutionOf("runtimeClasspath") | ||
} | ||
usage("java-runtime") { | ||
fromResolutionResult() | ||
} | ||
} | ||
} | ||
} | ||
|
||
val signingKey: String? by project | ||
|
||
if (signingKey != null) { | ||
signing { | ||
useInMemoryPgpKeys(signingKey, null) | ||
sign(*publishing.publications.toTypedArray()) | ||
} | ||
} | ||
|
||
val ossrhUser: String? by project | ||
val ossrhPassword: String? by project | ||
val stagingProfile: String? by project | ||
|
||
val enablePublishing = ossrhUser != null && ossrhPassword != null && stagingProfile != null | ||
|
||
if (enablePublishing) { | ||
nexusPublishing { | ||
repositories.sonatype { | ||
username.set(ossrhUser) | ||
password.set(ossrhPassword) | ||
stagingProfileId.set(stagingProfile) | ||
} | ||
} | ||
} | ||
|
||
val build by tasks | ||
val clean by tasks | ||
|
||
build.mustRunAfter(clean) | ||
|
||
val rebuild = tasks.register<Task>("rebuild") { | ||
group = "build" | ||
dependsOn(clean, build) | ||
} | ||
|
||
// Only enable publishing task for properly configured projects | ||
val publishingTasks = tasks.withType<PublishToMavenRepository> { | ||
enabled = ossrhUser?.isNotEmpty() == true || name.contains("local", true) | ||
mustRunAfter(rebuild) | ||
dependsOn(rebuild) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters