From 7daeedb9ff046b9093b982248e401257a0f1574e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 9 May 2019 22:05:23 +0300 Subject: [PATCH] Fixed build for publish --- build.gradle.kts | 3 +- .../main/kotlin/npm-artifactory.gradle.kts | 33 ----- .../src/main/kotlin/npm-bintray.gradle.kts | 104 -------------- .../src/main/kotlin/npm-publish.gradle.kts | 134 ++++++++++++++++++ 4 files changed, 135 insertions(+), 139 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/npm-artifactory.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/npm-bintray.gradle.kts create mode 100644 buildSrc/src/main/kotlin/npm-publish.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 8494144e..4fc08ab3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,6 @@ allprojects { subprojects { if (name.startsWith("dataforge")) { - apply(plugin = "npm-bintray") - apply(plugin = "npm-artifactory") + apply(plugin = "npm-publish") } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/npm-artifactory.gradle.kts b/buildSrc/src/main/kotlin/npm-artifactory.gradle.kts deleted file mode 100644 index 27e5ebce..00000000 --- a/buildSrc/src/main/kotlin/npm-artifactory.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -import groovy.lang.GroovyObject -import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig -import org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig - -plugins { - id("com.jfrog.artifactory") -} - -artifactory { - val artifactoryUser: String? by project - val artifactoryPassword: String? by project - val artifactoryContextUrl = "http://npm.mipt.ru:8081/artifactory" - - setContextUrl(artifactoryContextUrl)//The base Artifactory URL if not overridden by the publisher/resolver - publish(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "gradle-dev-local") - setProperty("username", artifactoryUser) - setProperty("password", artifactoryPassword) - }) - - defaults(delegateClosureOf{ - invokeMethod("publications", arrayOf("jvm", "js", "kotlinMultiplatform", "metadata")) - }) - }) - resolve(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "gradle-dev") - setProperty("username", artifactoryUser) - setProperty("password", artifactoryPassword) - }) - }) -} diff --git a/buildSrc/src/main/kotlin/npm-bintray.gradle.kts b/buildSrc/src/main/kotlin/npm-bintray.gradle.kts deleted file mode 100644 index a8987279..00000000 --- a/buildSrc/src/main/kotlin/npm-bintray.gradle.kts +++ /dev/null @@ -1,104 +0,0 @@ -@file:Suppress("UnstableApiUsage") - -import com.jfrog.bintray.gradle.BintrayExtension.PackageConfig -import com.jfrog.bintray.gradle.BintrayExtension.VersionConfig - -// Old bintray.gradle script converted to real Gradle plugin (precompiled script plugin) -// It now has own dependencies and support type safe accessors -// Syntax is pretty close to what we had in Groovy -// (excluding Property.set and bintray dynamic configs) - -plugins { - id("com.jfrog.bintray") - `maven-publish` -} - -val vcs = "https://github.com/mipt-npm/kmath" - -// Configure publishing -publishing { - repositories { - maven("https://bintray.com/mipt-npm/scientifik") - } - - // Process each publication we have in this project - publications.filterIsInstance().forEach { publication -> - - // use type safe pom config GSL insterad of old dynamic - 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") - } - } - developers { - developer { - id.set("MIPT-NPM") - name.set("MIPT nuclear physics methods laboratory") - organization.set("MIPT") - organizationUrl.set("http://npm.mipt.ru") - } - - } - scm { - url.set(vcs) - } - } - - } -} - -bintray { - // delegates for runtime properties - val bintrayUser: String? by project - val bintrayApiKey: String? by project - user = bintrayUser ?: System.getenv("BINTRAY_USER") - key = bintrayApiKey ?: 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(delegateClosureOf { - userOrg = "mipt-npm" - repo = "dataforge" - name = project.name - issueTrackerUrl = "https://github.com/altavir/dataforge-core/issues" - setLicenses("Apache-2.0") - vcsUrl = vcs - version(delegateClosureOf { - name = project.version.toString() - vcsTag = project.version.toString() - released = java.util.Date().toString() - }) - }) - - tasks { - bintrayUpload { - dependsOn(publishToMavenLocal) - doFirst { - setPublications(project.publishing.publications - .filterIsInstance() - .filter { !it.name.contains("-test") && it.name != "kotlinMultiplatform" } - .map { - println("""Uploading artifact "${it.groupId}:${it.artifactId}:${it.version}" from publication "${it.name}""") - it.name //https://github.com/bintray/gradle-bintray-plugin/issues/256 - }) - } - } - - } - - val publications = project.publishing.publications.filter { !it.name.contains("-test") }.map { - println("Uploading artifact '$it.groupId:$it.artifactId:$it.version' from publication '$it.name'") - it.name.toString() - }.toTypedArray() - - setPublications(*publications) -} diff --git a/buildSrc/src/main/kotlin/npm-publish.gradle.kts b/buildSrc/src/main/kotlin/npm-publish.gradle.kts new file mode 100644 index 00000000..316a1c65 --- /dev/null +++ b/buildSrc/src/main/kotlin/npm-publish.gradle.kts @@ -0,0 +1,134 @@ +@file:Suppress("UnstableApiUsage") + +import com.jfrog.bintray.gradle.tasks.BintrayUploadTask +import groovy.lang.GroovyObject +import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact +import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig +import org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig + +// Old bintray.gradle script converted to real Gradle plugin (precompiled script plugin) +// It now has own dependencies and support type safe accessors +// Syntax is pretty close to what we had in Groovy +// (excluding Property.set and bintray dynamic configs) + +plugins { + `maven-publish` + id("com.jfrog.bintray") + id("com.jfrog.artifactory") +} + +val vcs = "https://github.com/altavir/dataforge-core" + +// Configure publishing +publishing { + repositories { + maven("https://bintray.com/mipt-npm/dataforge") + } + + // Process each publication we have in this project + publications.filterIsInstance().forEach { publication -> + + // use type safe pom config GSL insterad of old dynamic + 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") + } + } + developers { + developer { + id.set("MIPT-NPM") + name.set("MIPT nuclear physics methods laboratory") + organization.set("MIPT") + organizationUrl.set("http://npm.mipt.ru") + } + + } + scm { + url.set(vcs) + } + } + } + +} + +bintray { + user = findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER") + key = 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 = "dataforge" + name = project.name + issueTrackerUrl = "https://github.com/altavir/dataforge-core/issues" + setLicenses("Apache-2.0") + vcsUrl = vcs + version.apply { + name = project.version.toString() + vcsTag = project.version.toString() + released = java.util.Date().toString() + } + } + + afterEvaluate { + setPublications(*publishing.publications.names.toTypedArray()) + } + + tasks { + bintrayUpload { + dependsOn(publishToMavenLocal) + } + } +} + +//workaround for bintray +tasks.withType { + doFirst { + publishing.publications + .filterIsInstance() + .forEach { publication -> + val moduleFile = buildDir.resolve("publications/${publication.name}/module.json") + if (moduleFile.exists()) { + publication.artifact(object : FileBasedMavenArtifact(moduleFile) { + override fun getDefaultExtension() = "module" + }) + } + } + } +} + +artifactory { + val artifactoryUser: String? by project + val artifactoryPassword: String? by project + val artifactoryContextUrl = "http://npm.mipt.ru:8081/artifactory" + + setContextUrl(artifactoryContextUrl)//The base Artifactory URL if not overridden by the publisher/resolver + publish(delegateClosureOf { + repository(delegateClosureOf { + setProperty("repoKey", "gradle-dev-local") + setProperty("username", artifactoryUser) + setProperty("password", artifactoryPassword) + }) + + defaults(delegateClosureOf { + invokeMethod("publications", arrayOf("jvm", "js", "kotlinMultiplatform", "metadata")) + }) + }) + resolve(delegateClosureOf { + repository(delegateClosureOf { + setProperty("repoKey", "gradle-dev") + setProperty("username", artifactoryUser) + setProperty("password", artifactoryPassword) + }) + }) +}