From 1fbf08cbfce0924f5d5b6e910de9733ee194a7da Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 13 Jul 2019 16:47:24 +0300 Subject: [PATCH] Added stubs for github package registry --- build.gradle.kts | 4 +- .../kotlin/scientifik/ScientifikExtension.kt | 1 + .../scientifik/ScientifikPublishPlugin.kt | 114 ++++++++++++------ 3 files changed, 80 insertions(+), 39 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6195eaf..6d851ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,14 +8,14 @@ plugins { } group = "scientifik" -version = "0.1.2" +version = "0.1.3" repositories { gradlePluginPortal() jcenter() } -val kotlinVersion = "1.3.40" +val kotlinVersion = "1.3.41" // Add plugins used in buildSrc as dependencies, also we should specify version only here dependencies { diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt index 0aebd20..eb19771 100644 --- a/src/main/kotlin/scientifik/ScientifikExtension.kt +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -1,6 +1,7 @@ package scientifik open class ScientifikExtension { + var githubProject: String? = null var vcs: String? = null var bintrayRepo: String? = null var kdoc: Boolean = true diff --git a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt index d2097d3..553fa15 100644 --- a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt +++ b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt @@ -9,6 +9,7 @@ import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact +import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import org.jetbrains.dokka.gradle.DokkaTask @@ -26,10 +27,16 @@ private val Project.bintrayRepo: String? ?: parent?.bintrayRepo ?: (findProperty("bintrayRepo") as? String) +private val Project.githubProject: String? + get() = extensions.findByType()?.vcs + ?: parent?.githubProject + ?: (findProperty("githubProject") as? String) + private val Project.vcs: String? get() = extensions.findByType()?.vcs ?: parent?.vcs ?: (findProperty("vcs") as? String) + ?: githubProject?.let { "https://github.com/mipt-npm/$it" } open class ScientifikPublishPlugin : Plugin { @@ -47,7 +54,7 @@ open class ScientifikPublishPlugin : Plugin { val bintrayRepo = project.bintrayRepo val vcs = project.vcs - if (bintrayRepo == null || vcs == null) { + if (vcs == null) { project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") return@afterEvaluate } @@ -56,10 +63,6 @@ open class ScientifikPublishPlugin : Plugin { project.plugins.apply("com.jfrog.artifactory") project.configure { - repositories { - maven("https://bintray.com/mipt-npm/$bintrayRepo") - } - // Process each publication we have in this project publications.filterIsInstance().forEach { publication -> @@ -90,6 +93,38 @@ open class ScientifikPublishPlugin : Plugin { } } } + + val githubUser: String? by project + val githubToken: String? by project + + val githubProject = project.githubProject + + 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().map { publication -> + tasks.register("publish${publication.name.capitalize()}ToGithub") { + group = "publishing" + this.publication = publication + this.repository = repository + } + } + + tasks.register("publishToGithub") { + group = "publishing" + dependsOn(githubPublishTasks) + } + + } + } } if (extension.kdoc) { @@ -176,38 +211,6 @@ open class ScientifikPublishPlugin : Plugin { } - project.configure { - user = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER") - key = project.findProperty("bintrayApiKey") as? String? ?: System.getenv("BINTRAY_API_KEY") - publish = true - override = true // for multi-platform Kotlin/Native publishing - - // We have to use delegateClosureOf because bintray supports only dynamic groovy syntax - // this is a problem of this plugin - pkg.apply { - userOrg = "mipt-npm" - repo = bintrayRepo - 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()!!.publications.names.toTypedArray()) - - -// project.tasks.figetByPath("bintrayUpload") { -// dependsOn(publishToMavenLocal) -// } - } - project.configure { val artifactoryUser: String? by project val artifactoryPassword: String? by project @@ -233,6 +236,43 @@ open class ScientifikPublishPlugin : Plugin { }) }) } + + if (bintrayRepo == null) { + project.logger.warn("[${project.name}] Bintray repository not defined") + } else { + + project.configure { + repositories { + maven("https://bintray.com/mipt-npm/$bintrayRepo") + } + } + + project.configure { + 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" + repo = bintrayRepo + 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()!!.publications.names.toTypedArray()) + } + } } } } \ No newline at end of file