-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Oztechan/CCC#3020] Fix Library publication issues
- Loading branch information
1 parent
a590779
commit d48553b
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,131 @@ | |
* Copyright (c) 2020 Mustafa Ozhan. All rights reserved. | ||
*/ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
import java.io.IOException | ||
import java.util.Properties | ||
|
||
plugins { | ||
libs.plugins.apply { | ||
alias(libs.plugins.kotlinMultiplatform).apply(false) | ||
alias(libs.plugins.kover) | ||
} | ||
`maven-publish` | ||
} | ||
|
||
allprojects { | ||
|
||
apply(plugin = rootProject.libs.plugins.kover.get().pluginId).also { | ||
rootProject.dependencies.add("kover", project(path)) | ||
} | ||
|
||
Library.apply { | ||
|
||
group = GROUP | ||
version = ProjectSettings.getVersionName(project) | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
val emptyJavadocJar by tasks.registering(Jar::class) { | ||
archiveClassifier.set("javadoc") | ||
} | ||
|
||
afterEvaluate { | ||
extensions.findByType<PublishingExtension>()?.apply { | ||
repositories { | ||
maven { | ||
url = uri(if (isReleaseBuild) RELEASE_URL else SNAPSHOT_URL) | ||
credentials { | ||
username = getSecret("MAVEN_USERNAME") | ||
password = getSecret("MAVEN_PASSWORD") | ||
} | ||
} | ||
} | ||
|
||
publications.withType<MavenPublication>().configureEach { | ||
artifact(emptyJavadocJar.get()) | ||
|
||
pom { | ||
name.set(NAME) | ||
description.set(DESCRIPTION) | ||
url.set(URL) | ||
|
||
licenses { | ||
license { | ||
name.set(LICENSE_NAME) | ||
url.set(LICENSE_URL) | ||
distribution.set(LICENSE_DISTRIBUTION) | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set(DEVELOPER_ID) | ||
name.set(DEVELOPER_NAME) | ||
email.set(DEVELOPER_EMAIL) | ||
} | ||
} | ||
scm { url.set(URL) } | ||
} | ||
} | ||
} | ||
|
||
extensions.findByType<PublishingExtension>()?.let { publishing -> | ||
val key = getSecret("GPG_KEY").replace("\\n", "\n") | ||
val password = getSecret("GPG_PASSWORD") | ||
|
||
extensions.findByType<SigningExtension>()?.apply { | ||
useInMemoryPgpKeys(key, password) | ||
sign(publishing.publications) | ||
} | ||
} | ||
|
||
tasks.withType<Sign>().configureEach { | ||
onlyIf { isReleaseBuild } | ||
} | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
allWarningsAsErrors = true | ||
} | ||
} | ||
} | ||
|
||
val isReleaseBuild: Boolean | ||
get() = System.getenv("GPG_KEY") != null | ||
|
||
fun getSecret( | ||
key: String, | ||
default: String = "secret" // these values can not be public | ||
): String = System.getenv(key).let { | ||
if (it.isNullOrEmpty()) { | ||
getSecretProperties()?.get(key)?.toString() ?: default | ||
} else { | ||
it | ||
} | ||
} | ||
|
||
fun getSecretProperties() = try { | ||
Properties().apply { load(file("key.properties").inputStream()) } | ||
} catch (e: IOException) { | ||
logger.debug(e.message, e) | ||
null | ||
} | ||
|
||
object Library { | ||
const val GROUP = "com.github.submob" | ||
const val URL = "https://github.com/SubMob/ScopeMob" | ||
const val NAME = "ScopeMob" | ||
const val DESCRIPTION = "Set of useful scope and higher-order functions" | ||
const val DEVELOPER_NAME = "Mustafa Ozhan" | ||
const val DEVELOPER_ID = "mustafaozhan" | ||
const val DEVELOPER_EMAIL = "[email protected]" | ||
const val LICENSE_NAME = "The Apache Software License, Version 2.0" | ||
const val LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.txt" | ||
const val LICENSE_DISTRIBUTION = "repo" | ||
const val RELEASE_URL = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" | ||
const val SNAPSHOT_URL = "https://s01.oss.sonatype.org/content/repositories/snapshots" | ||
} |