gradle-tools/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt

130 lines
4.9 KiB
Kotlin
Raw Normal View History

2019-06-28 16:22:11 +03:00
package scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
2020-03-09 13:06:40 +03:00
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
2019-06-28 16:22:11 +03:00
open class ScientifikPublishPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.plugins.apply("maven-publish")
2020-07-05 14:39:35 +03:00
project.afterEvaluate {
val githubProject = findProperty("githubProject") as? String
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/mipt-npm/$it" }
2019-06-28 16:22:11 +03:00
if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
2020-07-05 14:39:35 +03:00
return@afterEvaluate
2019-06-28 16:22:11 +03:00
}
project.configure<PublishingExtension> {
// Process each publication we have in this project
2020-03-09 13:06:40 +03:00
publications.withType<MavenPublication>().forEach { publication ->
@Suppress("UnstableApiUsage")
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
2019-06-28 16:22:11 +03:00
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
2019-06-28 16:22:11 +03:00
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
2019-06-28 16:22:11 +03:00
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
2020-03-09 13:06:40 +03:00
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
2019-11-01 22:06:41 +03:00
}
}
}
2019-06-28 16:22:11 +03:00
2020-07-05 14:39:35 +03:00
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
2020-03-09 13:06:40 +03:00
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser = project.findProperty("bintrayUser") as? String
val bintrayKey = project.findProperty("bintrayApiKey") as? String
2020-03-09 13:06:40 +03:00
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
2019-06-28 16:22:11 +03:00
}
val projectName = project.name
2020-03-09 13:06:40 +03:00
if (bintrayRepo != null && bintrayUser != null && bintrayKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
2019-06-28 16:22:11 +03:00
repositories {
maven {
2020-03-09 13:06:40 +03:00
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=0;override=1"
)
2020-03-09 13:06:40 +03:00
credentials {
username = bintrayUser
password = bintrayKey
2020-03-09 13:06:40 +03:00
}
}
}
}
}
2019-06-28 16:22:11 +03:00
}
}
}