From 5be55560cffe6815ef41ef71faf36d539ef07530 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 31 May 2019 13:03:00 +0300 Subject: [PATCH] Merged build config changes from dataforge --- build.gradle.kts | 17 +-- buildSrc/build.gradle.kts | 4 +- buildSrc/src/main/kotlin/Versions.kt | 3 +- .../main/kotlin/artifactory-config.gradle.kts | 38 ----- .../src/main/kotlin/bintray-config.gradle.kts | 97 ------------- .../src/main/kotlin/dokka-publish.gradle.kts | 74 ++++++++++ ...radle.kts => npm-multiplatform.gradle.kts} | 50 +------ .../src/main/kotlin/npm-publish.gradle.kts | 136 ++++++++++++++++++ kmath-core/build.gradle.kts | 2 +- kmath-coroutines/build.gradle.kts | 2 +- kmath-histograms/build.gradle.kts | 2 +- kmath-koma/build.gradle.kts | 2 +- kmath-memory/build.gradle.kts | 2 +- kmath-prob/build.gradle.kts | 2 +- settings.gradle.kts | 11 +- 15 files changed, 236 insertions(+), 206 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/artifactory-config.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/bintray-config.gradle.kts create mode 100644 buildSrc/src/main/kotlin/dokka-publish.gradle.kts rename buildSrc/src/main/kotlin/{multiplatform-config.gradle.kts => npm-multiplatform.gradle.kts} (51%) create mode 100644 buildSrc/src/main/kotlin/npm-publish.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 4ec4695f5..2fe3900ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -val kmathVersion by extra("0.1.2-dev-4") +val kmathVersion by extra("0.1.2") allprojects { repositories { @@ -11,19 +11,8 @@ allprojects { } subprojects { - // Actually, probably we should apply it to plugins explicitly - // We also can merge them to single kmath-publish plugin + apply(plugin = "dokka-publish") if (name.startsWith("kmath")) { - apply(plugin = "bintray-config") - apply(plugin = "artifactory-config") + apply(plugin = "npm-publish") } - // dokka { -// outputFormat = "html" -// outputDirectory = javadoc.destinationDir -// } -// -// task dokkaJar (type: Jar, dependsOn: dokka) { -// from javadoc . destinationDir -// classifier = "javadoc" -// } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 087a7b8a4..318189162 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,7 +12,9 @@ val kotlinVersion = "1.3.31" // Add plugins used in buildSrc as dependencies, also we should specify version only here dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.5") + implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.6") implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.9.18") implementation("com.moowork.gradle:gradle-node-plugin:1.3.1") + implementation("org.openjfx:javafx-plugin:0.0.7") } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 8279b081a..883af1203 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -5,6 +5,5 @@ object Versions { val ioVersion = "0.1.8" val coroutinesVersion = "1.2.1" val atomicfuVersion = "0.12.6" - // This version is not used and IDEA shows this property as unused - val dokkaVersion = "0.9.18" + val serializationVersion = "0.11.0" } diff --git a/buildSrc/src/main/kotlin/artifactory-config.gradle.kts b/buildSrc/src/main/kotlin/artifactory-config.gradle.kts deleted file mode 100644 index d792dffb7..000000000 --- a/buildSrc/src/main/kotlin/artifactory-config.gradle.kts +++ /dev/null @@ -1,38 +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")) - //TODO: This property is not available for ArtifactoryTask - //setProperty("publishBuildInfo", false) - setProperty("publishArtifacts", true) - setProperty("publishPom", true) - setProperty("publishIvy", false) - }) - }) - resolve(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "gradle-dev") - setProperty("username", artifactoryUser) - setProperty("password", artifactoryPassword) - }) - }) -} diff --git a/buildSrc/src/main/kotlin/bintray-config.gradle.kts b/buildSrc/src/main/kotlin/bintray-config.gradle.kts deleted file mode 100644 index b152d1639..000000000 --- a/buildSrc/src/main/kotlin/bintray-config.gradle.kts +++ /dev/null @@ -1,97 +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 = "scientifik" - name = "scientifik.kmath" - issueTrackerUrl = "https://github.com/mipt-npm/kmath/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 - }) - } - } - - } -} diff --git a/buildSrc/src/main/kotlin/dokka-publish.gradle.kts b/buildSrc/src/main/kotlin/dokka-publish.gradle.kts new file mode 100644 index 000000000..58048edb6 --- /dev/null +++ b/buildSrc/src/main/kotlin/dokka-publish.gradle.kts @@ -0,0 +1,74 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +plugins { + id("org.jetbrains.dokka") + `maven-publish` +} + +afterEvaluate { + + extensions.findByType()?.apply{ + val dokka by tasks.getting(DokkaTask::class) { + outputFormat = "html" + outputDirectory = "$buildDir/javadoc" + jdkVersion = 8 + + kotlinTasks { + // dokka fails to retrieve sources from MPP-tasks so we only define the jvm task + listOf(tasks.getByPath("compileKotlinJvm")) + } + sourceRoot { + // assuming only single source dir + path = sourceSets["commonMain"].kotlin.srcDirs.first().toString() + platforms = listOf("Common") + } + // although the JVM sources are now taken from the task, + // we still define the jvm source root to get the JVM marker in the generated html + sourceRoot { + // assuming only single source dir + path = sourceSets["jvmMain"].kotlin.srcDirs.first().toString() + platforms = listOf("JVM") + } + } + + val kdocJar by tasks.registering(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + dependsOn(dokka) + archiveClassifier.set("javadoc") + from("$buildDir/javadoc") + } + + configure { + + targets.all { + val publication = publications.findByName(name) as MavenPublication + + // Patch publications with fake javadoc + publication.artifact(kdocJar.get()) + } + } + } + + + extensions.findByType()?.apply{ + val dokka by tasks.getting(DokkaTask::class) { + outputFormat = "html" + outputDirectory = "$buildDir/javadoc" + jdkVersion = 8 + } + + val kdocJar by tasks.registering(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + dependsOn(dokka) + archiveClassifier.set("javadoc") + from("$buildDir/javadoc") + } + + configure { + publications.filterIsInstance().forEach { publication -> + publication.artifact(kdocJar.get()) + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/multiplatform-config.gradle.kts b/buildSrc/src/main/kotlin/npm-multiplatform.gradle.kts similarity index 51% rename from buildSrc/src/main/kotlin/multiplatform-config.gradle.kts rename to buildSrc/src/main/kotlin/npm-multiplatform.gradle.kts index b4bd1532b..20b096ab8 100644 --- a/buildSrc/src/main/kotlin/multiplatform-config.gradle.kts +++ b/buildSrc/src/main/kotlin/npm-multiplatform.gradle.kts @@ -1,5 +1,3 @@ -import org.gradle.kotlin.dsl.* - plugins { kotlin("multiplatform") `maven-publish` @@ -11,8 +9,6 @@ kotlin { compilations.all { kotlinOptions { jvmTarget = "1.8" - // This was used in kmath-koma, but probably if we need it better to apply it for all modules - freeCompilerArgs = listOf("-progressive") } } } @@ -34,35 +30,35 @@ kotlin { } } - sourceSets.invoke { - commonMain { + sourceSets { + val commonMain by getting { dependencies { api(kotlin("stdlib")) } } - commonTest { + val commonTest by getting { dependencies { implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) } } - "jvmMain" { + val jvmMain by getting { dependencies { api(kotlin("stdlib-jdk8")) } } - "jvmTest" { + val jvmTest by getting { dependencies { implementation(kotlin("test")) implementation(kotlin("test-junit")) } } - "jsMain" { + val jsMain by getting { dependencies { api(kotlin("stdlib-js")) } } - "jsTest" { + val jsTest by getting { dependencies { implementation(kotlin("test-js")) } @@ -76,38 +72,6 @@ kotlin { } } - // Create empty jar for sources classifier to satisfy maven requirements - val stubSources by tasks.registering(Jar::class){ - archiveClassifier.set("sources") - //from(sourceSets.main.get().allSource) - } - - // Create empty jar for javadoc classifier to satisfy maven requirements - val stubJavadoc by tasks.registering(Jar::class) { - archiveClassifier.set("javadoc") - } - - - publishing { - - publications.filterIsInstance().forEach { publication -> - if (publication.name == "kotlinMultiplatform") { - // for our root metadata publication, set artifactId with a package and project name - publication.artifactId = project.name - } else { - // for targets, set artifactId with a package, project name and target name (e.g. iosX64) - publication.artifactId = "${project.name}-${publication.name}" - } - } - - targets.all { - val publication = publications.findByName(name) as MavenPublication - - // Patch publications with fake javadoc - publication.artifact(stubJavadoc.get()) - } - } - // Apply JS test configuration val runJsTests by ext(false) 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 000000000..175f15f0b --- /dev/null +++ b/buildSrc/src/main/kotlin/npm-publish.gradle.kts @@ -0,0 +1,136 @@ +@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/mipt-npm/kmath" +val bintrayRepo = "https://bintray.com/mipt-npm/scientifik" + +// Configure publishing +publishing { + repositories { + maven(bintrayRepo) + } + + // Process each publication we have in this project + publications.filterIsInstance().forEach { publication -> + + // use type safe pom config GSL instead 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 = "scientifik" + 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 + 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) + }) + }) +} diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 383bcfa08..25507968c 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `multiplatform-config` + `npm-multiplatform` } kotlin.sourceSets { diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 5f7e01e0b..6ffaf4df6 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `multiplatform-config` + `npm-multiplatform` id("kotlinx-atomicfu") version Versions.atomicfuVersion } diff --git a/kmath-histograms/build.gradle.kts b/kmath-histograms/build.gradle.kts index cdae1ad09..21df4c26f 100644 --- a/kmath-histograms/build.gradle.kts +++ b/kmath-histograms/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `multiplatform-config` + `npm-multiplatform` } // Just an example how we can collapse nested DSL for simple declarations diff --git a/kmath-koma/build.gradle.kts b/kmath-koma/build.gradle.kts index 5942182d5..9b07fdcf2 100644 --- a/kmath-koma/build.gradle.kts +++ b/kmath-koma/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `multiplatform-config` + `npm-multiplatform` } repositories { diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index c42d35c3a..3fb56989c 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1,3 +1,3 @@ plugins { - `multiplatform-config` + `npm-multiplatform` } diff --git a/kmath-prob/build.gradle.kts b/kmath-prob/build.gradle.kts index e55247dc0..28ab2d6c7 100644 --- a/kmath-prob/build.gradle.kts +++ b/kmath-prob/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `multiplatform-config` + `npm-multiplatform` id("kotlinx-atomicfu") version Versions.atomicfuVersion } diff --git a/settings.gradle.kts b/settings.gradle.kts index 690d80b59..5adf75fa5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,15 +1,16 @@ pluginManagement { repositories { - mavenCentral() + jcenter() gradlePluginPortal() - //maven ("https://dl.bintray.com/kotlin/kotlin-eap") + maven("https://dl.bintray.com/kotlin/kotlin-eap") } resolutionStrategy { eachPlugin { when (requested.id.id) { - "kotlinx-atomicfu" -> { - useModule("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${requested.version}") - } + "kotlinx-atomicfu" -> useModule("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${requested.version}") + "kotlin-multiplatform" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + "kotlin2js" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + //"org.jetbrains.kotlin.frontend" -> useModule("org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.45") } } }