@@ -35,6 +35,17 @@ val signingKey = providers.gradleProperty("signingInMemoryKey")
3535 .orElse(providers.environmentVariable(" MAVEN_SIGNING_KEY" ))
3636val signingPassword = providers.gradleProperty(" signingInMemoryKeyPassword" )
3737 .orElse(providers.environmentVariable(" MAVEN_SIGNING_PASSWORD" ))
38+ val requireRemoteMavenPublishing = providers.gradleProperty(" reallyme.maven.requireRemote" )
39+ .map { it == " true" }
40+ .orElse(false )
41+
42+ fun nonBlank (value : String? ): String? = value?.trim()?.takeIf { it.isNotEmpty() }
43+
44+ val remoteMavenRepositoryUrlValue = nonBlank(remoteMavenRepositoryUrl.orNull)
45+ val remoteMavenUsernameValue = nonBlank(remoteMavenUsername.orNull)
46+ val remoteMavenPasswordValue = nonBlank(remoteMavenPassword.orNull)
47+ val signingKeyValue = nonBlank(signingKey.orNull)
48+ val signingPasswordValue = nonBlank(signingPassword.orNull)
3849
3950val requiredAndroidJniLibs = listOf (
4051 " arm64-v8a/libreallyme_codec_ffi.so" ,
@@ -198,6 +209,44 @@ tasks.withType<PublishToMavenRepository>().configureEach {
198209 dependsOn(" verifyReleaseAarContainsJniLibs" )
199210}
200211
212+ val verifyRemoteMavenPublishingConfigured = tasks.register(" verifyRemoteMavenPublishingConfigured" ) {
213+ group = " verification"
214+ description = " Verifies that remote Maven publishing credentials are configured."
215+ onlyIf { requireRemoteMavenPublishing.get() }
216+ doLast {
217+ val missing = buildList {
218+ if (remoteMavenRepositoryUrlValue == null ) {
219+ add(" REALLYME_MAVEN_REPOSITORY_URL or -Preallyme.maven.repositoryUrl" )
220+ }
221+ if (remoteMavenUsernameValue == null ) {
222+ add(" REALLYME_MAVEN_USERNAME or -Preallyme.maven.username" )
223+ }
224+ if (remoteMavenPasswordValue == null ) {
225+ add(" REALLYME_MAVEN_PASSWORD or -Preallyme.maven.password" )
226+ }
227+ if (signingKeyValue == null ) {
228+ add(" MAVEN_SIGNING_KEY or -PsigningInMemoryKey" )
229+ }
230+ if (signingPasswordValue == null ) {
231+ add(" MAVEN_SIGNING_PASSWORD or -PsigningInMemoryKeyPassword" )
232+ }
233+ }
234+ if (missing.isNotEmpty()) {
235+ throw GradleException (
236+ " remote Maven publishing is not configured; missing non-empty ${missing.joinToString(" , " )} "
237+ )
238+ }
239+ }
240+ }
241+
242+ tasks.named(" publish" ) {
243+ dependsOn(verifyRemoteMavenPublishingConfigured)
244+ }
245+
246+ tasks.withType<PublishToMavenRepository >().configureEach {
247+ dependsOn(verifyRemoteMavenPublishingConfigured)
248+ }
249+
201250publishing {
202251 publications {
203252 create<MavenPublication >(" release" ) {
@@ -237,22 +286,22 @@ publishing {
237286 name = " localRelease"
238287 url = layout.buildDirectory.dir(" repos/releases" ).get().asFile.toURI()
239288 }
240- if (remoteMavenRepositoryUrl.isPresent ) {
289+ if (remoteMavenRepositoryUrlValue != null ) {
241290 maven {
242291 name = " remoteRelease"
243- url = uri(remoteMavenRepositoryUrl.get() )
292+ url = uri(remoteMavenRepositoryUrlValue )
244293 credentials {
245- username = remoteMavenUsername.orNull
246- password = remoteMavenPassword.orNull
294+ username = remoteMavenUsernameValue
295+ password = remoteMavenPasswordValue
247296 }
248297 }
249298 }
250299 }
251300}
252301
253302signing {
254- if (signingKey.isPresent ) {
255- useInMemoryPgpKeys(signingKey.get(), signingPassword.orNull )
303+ if (signingKeyValue != null ) {
304+ useInMemoryPgpKeys(signingKeyValue, signingPasswordValue )
256305 sign(publishing.publications[" release" ])
257306 }
258307}
0 commit comments