Skip to content

Commit

Permalink
refactor maven central user/pass properties, to avoid weird Gradle er…
Browse files Browse the repository at this point in the history
…ror:

The following Gradle properties are missing for 'SonatypeRelease' credentials:
- SonatypeReleaseUsername
- SonatypeReleasePassword
  • Loading branch information
aSemy committed Sep 1, 2023
1 parent 972c3ee commit b1ca20c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ publishing {
//region Maven Central publishing/signing
publishing {
repositories {
if (mavenPublishing.mavenCentralCredentials.isPresent) {
val mavenCentralUsername = mavenPublishing.mavenCentralUsername.orNull
val mavenCentralPassword = mavenPublishing.mavenCentralPassword.orNull
if (!mavenCentralUsername.isNullOrBlank() && !mavenCentralPassword.isNullOrBlank()) {
maven(mavenPublishing.sonatypeReleaseUrl) {
name = "SonatypeRelease"
credentials(mavenPublishing.mavenCentralCredentials.get())
credentials {
username = mavenCentralUsername
password = mavenCentralPassword
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package buildsrc.settings

import java.io.File
import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.PasswordCredentials
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.kotlin.dsl.*
Expand All @@ -30,21 +28,13 @@ abstract class MavenPublishingSettings @Inject constructor(
}
}

private val mavenCentralUsername: Provider<String> =
val mavenCentralUsername: Provider<String> =
d2Prop("mavenCentralUsername")
.orElse(providers.environmentVariable("MAVEN_SONATYPE_USERNAME"))
private val mavenCentralPassword: Provider<String> =
val mavenCentralPassword: Provider<String> =
d2Prop("mavenCentralPassword")
.orElse(providers.environmentVariable("MAVEN_SONATYPE_PASSWORD"))

val mavenCentralCredentials: Provider<Action<PasswordCredentials>> =
providers.zip(mavenCentralUsername, mavenCentralPassword) { user, pass ->
Action<PasswordCredentials> {
username = user
password = pass
}
}

val signingKeyId: Provider<String> =
d2Prop("signing.keyId")
.orElse(providers.environmentVariable("MAVEN_SONATYPE_SIGNING_KEY_ID"))
Expand Down

0 comments on commit b1ca20c

Please sign in to comment.