Skip to content

Commit bee5af1

Browse files
committed
Fix publishing properly, hopefully. I got it all wrong before.
1 parent 1e5d055 commit bee5af1

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

.github/workflows/build_and_publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
java-version: '8'
2828
- name: Build with Gradle
2929
env:
30-
ORG_GRADLE_PROJECT_centralAuthHeaderName: Authorization
31-
ORG_GRADLE_PROJECT_centralAuthHeaderValue: Bearer ${{ secrets.CENTRAL_AUTH_TOKEN }}
30+
ORG_GRADLE_PROJECT_OSSRH_USERNAME: Bearer ${{ secrets.OSSRH_USERNAME }}
31+
ORG_GRADLE_PROJECT_OSSRH_PASSWORD: Bearer ${{ secrets.OSSRH_PASSWORD }}
3232
run: ./gradlew build publish
3333
- uses: actions/upload-artifact@v4
3434
with:

build.gradle.kts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,43 @@ artifacts {
380380

381381
publishing {
382382
repositories {
383+
//only register maven.daporkchop.net repository if these environment variables are set
384+
val ossrhMavenUsername = (project.properties["OSSRH_USERNAME"] ?: System.getenv("OSSRH_USERNAME")) as String?
385+
val ossrhMavenPassword = (project.properties["OSSRH_PASSWORD"] ?: System.getenv("OSSRH_PASSWORD")) as String?
383386
maven {
384-
name = "central"
387+
name = "ossrh-staging-api"
385388

386-
val local = properties["centralAuthHeaderName"] == null
389+
val local = ossrhMavenUsername == null || ossrhMavenPassword == null
387390
if (local) {
388391
logger.warn("Username or password not set, publishing to local repository in build/mvnrepo/")
389392
}
390393
val localUrl = "$buildDir/mvnrepo"
391-
val releasesRepoUrl = "https://central.sonatype.com/api/v1/publisher/upload"
392-
val snapshotsRepoUrl = "https://central.sonatype.com/api/v1/publisher/upload"
394+
val releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
395+
//NOTE:
396+
//
397+
//Consuming Via Gradle⚓︎
398+
//
399+
//Configure your build.gradle file with the following:
400+
//
401+
//repositories {
402+
// maven {
403+
// name = 'Central Portal Snapshots'
404+
// url = 'https://central.sonatype.com/repository/maven-snapshots/'
405+
//
406+
// // Only search this repository for the specific dependency
407+
// content {
408+
// includeModule("<the snapshot's groupId>", "<the snapshot's artifactId>")
409+
// }
410+
// }
411+
// mavenCentral()
412+
//}
413+
val snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
393414

394415
setUrl(if (local) localUrl else if (doRelease.toBoolean()) releasesRepoUrl else snapshotsRepoUrl)
395416
if (!local) {
396-
credentials(HttpHeaderCredentials::class)
397-
authentication {
398-
create<HttpHeaderAuthentication>("header")
417+
credentials {
418+
username = ossrhMavenUsername
419+
password = ossrhMavenPassword
399420
}
400421
}
401422
}
@@ -496,7 +517,7 @@ publishing {
496517
// see https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing_maven:conditional_publishing
497518
tasks.withType<PublishToMavenRepository>().configureEach {
498519
val predicate = provider {
499-
(publication == publications["mod"] && repository == repositories.findByName("central")) ||
520+
(publication == publications["mod"] && repository == repositories.findByName("ossrh-staging-api")) ||
500521
(publication == publications["versionedMod"] && repository == repositories.findByName("DaPorkchop_"))
501522
}
502523
onlyIf("publishing mod to Sonatype repository, and versioned mod to DaPorkchop_ repository") {

0 commit comments

Comments
 (0)