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
|
2019-07-13 16:47:24 +03:00
|
|
|
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
|
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.register
|
|
|
|
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")
|
2019-07-20 20:39:26 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
project.run {
|
|
|
|
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
|
|
|
|
2019-07-13 16:47:24 +03:00
|
|
|
if (vcs == null) {
|
2019-07-07 14:23:10 +03:00
|
|
|
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
|
2019-08-09 11:51:30 +03:00
|
|
|
return@apply
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
|
2019-07-07 14:23:10 +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 ->
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-07-07 14:23:10 +03:00
|
|
|
@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
|
|
|
}
|
2019-07-07 14:23:10 +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
|
|
|
|
2019-07-07 14:23:10 +03:00
|
|
|
}
|
|
|
|
scm {
|
|
|
|
url.set(vcs)
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-13 16:47:24 +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}]")
|
2019-07-13 16:47:24 +03:00
|
|
|
repositories {
|
2020-03-09 13:06:40 +03:00
|
|
|
val githubMavenRepository = maven {
|
2019-07-13 16:47:24 +03:00
|
|
|
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-07-13 16:47:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
val githubPublishTasks = publications.filterIsInstance<MavenPublication>().map { publication ->
|
|
|
|
tasks.register<PublishToMavenRepository>("publish${publication.name.capitalize()}ToGithub") {
|
|
|
|
group = "publishing"
|
|
|
|
this.publication = publication
|
2020-03-09 13:06:40 +03:00
|
|
|
this.repository = githubMavenRepository
|
2019-07-13 16:47:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<PublishToMavenRepository>("publishToGithub") {
|
|
|
|
group = "publishing"
|
|
|
|
dependsOn(githubPublishTasks)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
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
|
|
|
}
|
2019-07-07 14:23:10 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
|
if (bintrayRepo != null && bintrayUser != null && bintrayKey != null) {
|
|
|
|
project.logger.info("Adding bintray publishing to project [${project.name}]")
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-07-13 16:47:24 +03:00
|
|
|
repositories {
|
2020-03-09 13:06:40 +03:00
|
|
|
val bintrayMavenRepository = maven {
|
|
|
|
name = "bintray"
|
|
|
|
uri("https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/${project.name}/;publish=0;override=1")
|
|
|
|
credentials {
|
|
|
|
this.username = bintrayUser
|
|
|
|
this.password = bintrayKey
|
|
|
|
}
|
|
|
|
}
|
2019-07-13 16:47:24 +03:00
|
|
|
|
2020-03-09 13:06:40 +03:00
|
|
|
val bintrayPublishTasks = publications.withType<MavenPublication>().map { publication ->
|
|
|
|
tasks.register<PublishToMavenRepository>("publish${publication.name.capitalize()}ToBintray") {
|
|
|
|
group = "publishing"
|
|
|
|
this.publication = publication
|
|
|
|
this.repository = bintrayMavenRepository
|
|
|
|
}
|
2019-07-13 16:47:24 +03:00
|
|
|
}
|
|
|
|
|
2020-03-09 13:06:40 +03:00
|
|
|
tasks.register<PublishToMavenRepository>("publishToBintray") {
|
|
|
|
group = "publishing"
|
|
|
|
dependsOn(bintrayPublishTasks)
|
|
|
|
}
|
2019-11-01 22:57:53 +03:00
|
|
|
}
|
2019-07-13 16:47:24 +03:00
|
|
|
}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|