@@ -92,7 +92,7 @@ val testRepositoryDir = project.layout.buildDirectory.dir("testRepository")
9292
9393publishing {
9494 repositories {
95- addSonatypeRepository ()
95+ addPublishingRepositoryIfPresent ()
9696
9797 /* *
9898 * Maven repository in build directory to check published artifacts.
@@ -232,26 +232,21 @@ fun MavenPublication.signPublicationIfKeyPresent() {
232232 }
233233}
234234
235- fun RepositoryHandler.addSonatypeRepository () {
236- maven {
237- url = mavenRepositoryUri()
238- credentials {
239- username = getSensitiveProperty(" libs.sonatype.user" )
240- password = getSensitiveProperty(" libs.sonatype.password" )
235+ // Artifacts are published to an intermediate repo (libs.repo.url) first,
236+ // and then deployed to the central portal.
237+ fun RepositoryHandler.addPublishingRepositoryIfPresent () {
238+ val repositoryUrl = getSensitiveProperty(" libs.repo.url" )
239+ if (! repositoryUrl.isNullOrBlank()) {
240+ maven {
241+ url = uri(repositoryUrl)
242+ credentials {
243+ username = getSensitiveProperty(" libs.repo.user" )
244+ password = getSensitiveProperty(" libs.repo.password" )
245+ }
241246 }
242247 }
243248}
244249
245- fun mavenRepositoryUri (): URI {
246- // TODO -SNAPSHOT detection can be made here as well
247- val repositoryId: String? = System .getenv(" libs.repository.id" )
248- return if (repositoryId == null ) {
249- URI (" https://oss.sonatype.org/service/local/staging/deploy/maven2/" )
250- } else {
251- URI (" https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId " )
252- }
253- }
254-
255250fun getSensitiveProperty (name : String ): String? {
256251 return findProperty(name) as ? String ? : System .getenv(name)
257252}
0 commit comments