1 /* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 @file:Suppress("UnstableApiUsage") 6 7 import org.gradle.api.* 8 import org.gradle.api.artifacts.dsl.* 9 import org.gradle.api.provider.* 10 import org.gradle.api.publish.maven.* 11 import org.gradle.plugins.signing.* 12 import java.net.* 13 14 // Pom configuration 15 bynull16infix fun <T> Property<T>.by(value: T) { 17 set(value) 18 } 19 configureMavenCentralMetadatanull20fun MavenPom.configureMavenCentralMetadata(project: Project) { 21 name by project.name 22 description by "AtomicFU utilities" 23 url by "https://github.com/Kotlin/kotlinx.atomicfu" 24 25 licenses { 26 license { 27 name by "The Apache Software License, Version 2.0" 28 url by "https://www.apache.org/licenses/LICENSE-2.0.txt" 29 distribution by "repo" 30 } 31 } 32 33 developers { 34 developer { 35 id by "JetBrains" 36 name by "JetBrains Team" 37 organization by "JetBrains" 38 organizationUrl by "https://www.jetbrains.com" 39 } 40 } 41 42 scm { 43 url by "https://github.com/Kotlin/kotlinx.atomicfu" 44 } 45 } 46 mavenRepositoryUrinull47fun mavenRepositoryUri(): URI { 48 val repositoryId: String? = System.getenv("libs.repository.id") 49 return if (repositoryId == null) { 50 // Using implicitly created staging, for MPP it's likely to be a mistake because 51 // publication on TeamCity will create 3 independent staging repositories 52 URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") 53 } else { 54 URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId") 55 } 56 } 57 configureMavenPublicationnull58fun configureMavenPublication(rh: RepositoryHandler, project: Project) { 59 rh.maven { 60 url = mavenRepositoryUri() 61 credentials { 62 username = project.getSensitiveProperty("libs.sonatype.user") 63 password = project.getSensitiveProperty("libs.sonatype.password") 64 } 65 } 66 } 67 signPublicationIfKeyPresentnull68fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) { 69 val keyId = project.getSensitiveProperty("libs.sign.key.id") 70 val signingKey = project.getSensitiveProperty("libs.sign.key.private") 71 val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase") 72 if (!signingKey.isNullOrBlank()) { 73 project.extensions.configure<SigningExtension>("signing") { 74 useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) 75 sign(publication) 76 } 77 } 78 } 79 getSensitivePropertynull80private fun Project.getSensitiveProperty(name: String): String? { 81 return project.findProperty(name) as? String ?: System.getenv(name) 82 } 83