2019-06-28 16:22:11 +03:00
|
|
|
package scientifik
|
|
|
|
|
|
|
|
import com.jfrog.bintray.gradle.BintrayExtension
|
|
|
|
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
|
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.api.publish.PublishingExtension
|
|
|
|
import org.gradle.api.publish.maven.MavenPublication
|
|
|
|
import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact
|
2019-07-13 16:47:24 +03:00
|
|
|
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
|
2019-06-28 16:22:11 +03:00
|
|
|
import org.gradle.kotlin.dsl.*
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
2019-07-21 13:31:11 +03:00
|
|
|
val bintrayRepo = if (project.version.toString().contains("dev")) {
|
|
|
|
"dev"
|
|
|
|
} else {
|
2019-08-09 11:51:30 +03:00
|
|
|
findProperty("bintrayRepo") as? String
|
2019-07-21 13:31:11 +03:00
|
|
|
}
|
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
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 18:06:24 +03:00
|
|
|
project.plugins.apply("com.jfrog.bintray")
|
|
|
|
|
2019-07-07 14:23:10 +03:00
|
|
|
project.configure<PublishingExtension> {
|
|
|
|
// Process each publication we have in this project
|
|
|
|
publications.filterIsInstance<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) {
|
|
|
|
repositories {
|
|
|
|
val repository = maven {
|
|
|
|
name = "github"
|
|
|
|
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
|
|
|
|
credentials {
|
|
|
|
username = githubUser
|
|
|
|
password = githubToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val githubPublishTasks = publications.filterIsInstance<MavenPublication>().map { publication ->
|
|
|
|
tasks.register<PublishToMavenRepository>("publish${publication.name.capitalize()}ToGithub") {
|
|
|
|
group = "publishing"
|
|
|
|
this.publication = publication
|
|
|
|
this.repository = repository
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<PublishToMavenRepository>("publishToGithub") {
|
|
|
|
group = "publishing"
|
|
|
|
dependsOn(githubPublishTasks)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
|
2019-08-09 11:51:30 +03:00
|
|
|
pluginManager.withPlugin("scientifik.mpp"){
|
2019-10-04 18:38:15 +03:00
|
|
|
tasks.filterIsInstance<BintrayUploadTask>().forEach {
|
2019-08-09 11:51:30 +03:00
|
|
|
it.doFirst {
|
|
|
|
publications.filterIsInstance<MavenPublication>()
|
|
|
|
.forEach { publication ->
|
|
|
|
val moduleFile =
|
|
|
|
buildDir.resolve("publications/${publication.name}/module.json")
|
|
|
|
if (moduleFile.exists()) {
|
|
|
|
publication.artifact(object : FileBasedMavenArtifact(moduleFile) {
|
|
|
|
override fun getDefaultExtension() = "module"
|
|
|
|
})
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
2019-08-09 11:51:30 +03:00
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-07 14:23:10 +03:00
|
|
|
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
|
2019-07-13 16:47:24 +03:00
|
|
|
if (bintrayRepo == null) {
|
|
|
|
project.logger.warn("[${project.name}] Bintray repository not defined")
|
|
|
|
} else {
|
|
|
|
|
|
|
|
project.configure<PublishingExtension> {
|
|
|
|
repositories {
|
|
|
|
maven("https://bintray.com/mipt-npm/$bintrayRepo")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project.configure<BintrayExtension> {
|
|
|
|
user = project.findProperty("bintrayUser") as? String?
|
|
|
|
key = project.findProperty("bintrayApiKey") as? String?
|
|
|
|
publish = true
|
|
|
|
override = true
|
|
|
|
|
|
|
|
// We have to use delegateClosureOf because bintray supports only dynamic groovy syntax
|
|
|
|
// this is a problem of this plugin
|
|
|
|
pkg.apply {
|
|
|
|
userOrg = "mipt-npm"
|
2019-07-21 13:31:11 +03:00
|
|
|
repo = bintrayRepo
|
2019-07-13 16:47:24 +03:00
|
|
|
name = project.name
|
|
|
|
issueTrackerUrl = "$vcs/issues"
|
|
|
|
setLicenses("Apache-2.0")
|
|
|
|
vcsUrl = vcs
|
|
|
|
version.apply {
|
|
|
|
name = project.version.toString()
|
|
|
|
vcsTag = project.version.toString()
|
|
|
|
released = java.util.Date().toString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//workaround bintray bug
|
|
|
|
setPublications(*project.extensions.findByType<PublishingExtension>()!!.publications.names.toTypedArray())
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 16:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|