From 1cdf19e53396929e0f04444dd0637dcfd549ee57 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 30 Apr 2019 14:57:48 +0300 Subject: [PATCH] Switched to buildSrc plugin --- build.gradle.kts | 218 +----------------- buildSrc/build.gradle.kts | 19 ++ buildSrc/settings.gradle.kts | 0 buildSrc/src/main/kotlin/Versions.kt | 10 + .../main/kotlin/artifactory-config.gradle.kts | 38 +++ .../src/main/kotlin/bintray-config.gradle.kts | 97 ++++++++ buildSrc/src/main/kotlin/js-test.gradle.kts | 44 ++++ .../kotlin/multiplatform-config.gradle.kts | 118 ++++++++++ dataforge-context/build.gradle.kts | 4 +- dataforge-data/build.gradle.kts | 4 +- dataforge-io/build.gradle.kts | 6 +- dataforge-meta/build.gradle.kts | 2 +- .../hep/dataforge/meta/MetaDelegateTest.kt | 2 +- dataforge-output/build.gradle.kts | 2 +- .../dataforge-output-html/build.gradle.kts | 2 +- dataforge-scripting/build.gradle.kts | 2 +- dataforge-workspace/build.gradle.kts | 2 +- settings.gradle.kts | 2 +- 18 files changed, 346 insertions(+), 226 deletions(-) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/Versions.kt create mode 100644 buildSrc/src/main/kotlin/artifactory-config.gradle.kts create mode 100644 buildSrc/src/main/kotlin/bintray-config.gradle.kts create mode 100644 buildSrc/src/main/kotlin/js-test.gradle.kts create mode 100644 buildSrc/src/main/kotlin/multiplatform-config.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 1cd8b00e..e1ac4fcc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,224 +1,18 @@ -import com.moowork.gradle.node.NodeExtension -import com.moowork.gradle.node.npm.NpmTask -import com.moowork.gradle.node.task.NodeTask -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -buildscript { - val kotlinVersion: String by rootProject.extra("1.3.21") - val ioVersion: String by rootProject.extra("0.1.5") - val coroutinesVersion: String by rootProject.extra("1.1.1") - val atomicfuVersion: String by rootProject.extra("0.12.1") - val dokkaVersion: String by rootProject.extra("0.9.17") - val serializationVersion: String by rootProject.extra("0.10.0") - - repositories { - jcenter() - maven("https://dl.bintray.com/kotlin/kotlin-eap") - } - - dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4+") - classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") - classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion") - classpath("org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.45") - classpath("org.openjfx:javafx-plugin:0.0.7") - } -} - -plugins { - id("com.jfrog.artifactory") version "4.8.1" apply false - id("com.moowork.node") version "1.3.1" apply false -// id("org.jetbrains.kotlin.multiplatform") apply false -} +val dataforgeVersion by extra("0.1.2-dev-5") allprojects { - apply(plugin = "maven") - apply(plugin = "maven-publish") - apply(plugin = "com.jfrog.artifactory") - repositories { jcenter() maven("https://kotlin.bintray.com/kotlinx") } group = "hep.dataforge" - version = "0.1.2-dev-5" + version = dataforgeVersion } subprojects { - - if(name.startsWith("dataforge")){ - // apply bintray configuration - apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") - - //apply artifactory configuration - apply(from = "${rootProject.rootDir}/gradle/artifactory.gradle") - - } - - // dokka { -// outputFormat = "html" -// outputDirectory = javadoc.destinationDir -// } -// -// task dokkaJar (type: Jar, dependsOn: dokka) { -// from javadoc . destinationDir -// classifier = "javadoc" -// } - - // 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") - } - - tasks.withType { - kotlinOptions { - jvmTarget = "1.8" - } - } - - - afterEvaluate { - extensions.findByType()?.apply { - jvm { - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } - } - } - - js { - compilations.all { - tasks.getByName(compileKotlinTaskName) { - kotlinOptions { - metaInfo = true - sourceMap = true - sourceMapEmbedSources = "always" - moduleKind = "commonjs" - } - } - } - - configure(listOf(compilations["main"])) { - tasks.getByName(compileKotlinTaskName) { - kotlinOptions { - main = "call" - } - } - } - - - val runJsTests by ext(false) - - if(runJsTests) { - apply(plugin = "com.moowork.node") - configure { - nodeModulesDir = file("$buildDir/node_modules") - } - - val compileKotlinJs by tasks.getting(Kotlin2JsCompile::class) - val compileTestKotlinJs by tasks.getting(Kotlin2JsCompile::class) - - val populateNodeModules by tasks.registering(Copy::class) { - dependsOn(compileKotlinJs) - from(compileKotlinJs.destinationDir) - - compilations["test"].runtimeDependencyFiles.forEach { - if (it.exists() && !it.isDirectory) { - from(zipTree(it.absolutePath).matching { include("*.js") }) - } - } - - into("$buildDir/node_modules") - } - - val installMocha by tasks.registering(NpmTask::class) { - setWorkingDir(buildDir) - setArgs(listOf("install", "mocha")) - } - - val runMocha by tasks.registering(NodeTask::class) { - dependsOn(compileTestKotlinJs, populateNodeModules, installMocha) - setScript(file("$buildDir/node_modules/mocha/bin/mocha")) - setArgs(listOf(compileTestKotlinJs.outputFile)) - } - - tasks["jsTest"].dependsOn(runMocha) - } - } - - sourceSets { - - val commonMain by getting { - dependencies { - api(kotlin("stdlib")) - } - } - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - val jvmMain by getting { - dependencies { - api(kotlin("stdlib-jdk8")) - } - } - val jvmTest by getting { - dependencies { - implementation(kotlin("test")) - implementation(kotlin("test-junit")) - } - } - val jsMain by getting { - dependencies { - api(kotlin("stdlib-js")) - } - } - val jsTest by getting { - dependencies { - implementation(kotlin("test-js")) - } - } - } - - targets.all { - sourceSets.all { - languageSettings.progressiveMode = true - } - } - - configure { - - 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()) - } - } - } - } - + if (name.startsWith("dataforge")) { + apply(plugin = "bintray-config") + apply(plugin = "artifactory-config") + } } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..7accd39e --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() + jcenter() +} + +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("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") + implementation("com.moowork.gradle:gradle-node-plugin:1.3.1") + implementation("org.openjfx:javafx-plugin:0.0.7") +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 00000000..f09472ba --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,10 @@ +// Instead of defining runtime properties and use them dynamically +// define version in buildSrc and have autocompletion and compile-time check +// Also dependencies itself can be moved here +object Versions { + val ioVersion = "0.1.8" + val coroutinesVersion = "1.2.1" + val atomicfuVersion = "0.12.6" + 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 new file mode 100644 index 00000000..d792dffb --- /dev/null +++ b/buildSrc/src/main/kotlin/artifactory-config.gradle.kts @@ -0,0 +1,38 @@ +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 new file mode 100644 index 00000000..b152d163 --- /dev/null +++ b/buildSrc/src/main/kotlin/bintray-config.gradle.kts @@ -0,0 +1,97 @@ +@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/js-test.gradle.kts b/buildSrc/src/main/kotlin/js-test.gradle.kts new file mode 100644 index 00000000..61759a28 --- /dev/null +++ b/buildSrc/src/main/kotlin/js-test.gradle.kts @@ -0,0 +1,44 @@ +import com.moowork.gradle.node.npm.NpmTask +import com.moowork.gradle.node.task.NodeTask +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile + +plugins { + id("com.moowork.node") + kotlin("multiplatform") +} + +node { + nodeModulesDir = file("$buildDir/node_modules") +} + +val compileKotlinJs by tasks.getting(Kotlin2JsCompile::class) +val compileTestKotlinJs by tasks.getting(Kotlin2JsCompile::class) + +val populateNodeModules by tasks.registering(Copy::class) { + dependsOn(compileKotlinJs) + from(compileKotlinJs.destinationDir) + + kotlin.js().compilations["test"].runtimeDependencyFiles.forEach { + if (it.exists() && !it.isDirectory) { + from(zipTree(it.absolutePath).matching { include("*.js") }) + } + } + + into("$buildDir/node_modules") +} + +val installMocha by tasks.registering(NpmTask::class) { + setWorkingDir(buildDir) + setArgs(listOf("install", "mocha")) +} + +val runMocha by tasks.registering(NodeTask::class) { + dependsOn(compileTestKotlinJs, populateNodeModules, installMocha) + setScript(file("$buildDir/node_modules/mocha/bin/mocha")) + setArgs(listOf(compileTestKotlinJs.outputFile)) +} + +tasks["jsTest"].dependsOn(runMocha) + + diff --git a/buildSrc/src/main/kotlin/multiplatform-config.gradle.kts b/buildSrc/src/main/kotlin/multiplatform-config.gradle.kts new file mode 100644 index 00000000..b4bd1532 --- /dev/null +++ b/buildSrc/src/main/kotlin/multiplatform-config.gradle.kts @@ -0,0 +1,118 @@ +import org.gradle.kotlin.dsl.* + +plugins { + kotlin("multiplatform") + `maven-publish` +} + + +kotlin { + jvm { + 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") + } + } + } + + js { + compilations.all { + kotlinOptions { + metaInfo = true + sourceMap = true + sourceMapEmbedSources = "always" + moduleKind = "commonjs" + } + } + + compilations.named("main") { + kotlinOptions { + main = "call" + } + } + } + + sourceSets.invoke { + commonMain { + dependencies { + api(kotlin("stdlib")) + } + } + commonTest { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + "jvmMain" { + dependencies { + api(kotlin("stdlib-jdk8")) + } + } + "jvmTest" { + dependencies { + implementation(kotlin("test")) + implementation(kotlin("test-junit")) + } + } + "jsMain" { + dependencies { + api(kotlin("stdlib-js")) + } + } + "jsTest" { + dependencies { + implementation(kotlin("test-js")) + } + } + } + + targets.all { + sourceSets.all { + languageSettings.progressiveMode = true + languageSettings.enableLanguageFeature("InlineClasses") + } + } + + // 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) + + if (runJsTests) { + apply(plugin = "js-test") + } + +} diff --git a/dataforge-context/build.gradle.kts b/dataforge-context/build.gradle.kts index df56273e..d91d3197 100644 --- a/dataforge-context/build.gradle.kts +++ b/dataforge-context/build.gradle.kts @@ -1,10 +1,10 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } description = "Context and provider definitions" -val coroutinesVersion: String by rootProject.extra +val coroutinesVersion: String = Versions.coroutinesVersion kotlin { jvm() diff --git a/dataforge-data/build.gradle.kts b/dataforge-data/build.gradle.kts index f0598595..97cb7143 100644 --- a/dataforge-data/build.gradle.kts +++ b/dataforge-data/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } -val coroutinesVersion: String by rootProject.extra +val coroutinesVersion: String = Versions.coroutinesVersion kotlin { jvm() diff --git a/dataforge-io/build.gradle.kts b/dataforge-io/build.gradle.kts index 1b57774d..4104e1c4 100644 --- a/dataforge-io/build.gradle.kts +++ b/dataforge-io/build.gradle.kts @@ -1,12 +1,12 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } description = "IO for meta" -val ioVersion: String by rootProject.extra -val serializationVersion: String by rootProject.extra +val ioVersion: String = Versions.ioVersion +val serializationVersion: String = Versions.serializationVersion kotlin { jvm() diff --git a/dataforge-meta/build.gradle.kts b/dataforge-meta/build.gradle.kts index 99108991..37aa617e 100644 --- a/dataforge-meta/build.gradle.kts +++ b/dataforge-meta/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } description = "Meta definition and basic operations on meta" diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt index 64cc9ad3..997a13e3 100644 --- a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt @@ -23,7 +23,7 @@ class MetaDelegateTest { override val config: Config = Config() var myValue by string() var safeValue by double(2.2) - var enumValue by config.enum(TestEnum.YES) + var enumValue by enum(TestEnum.YES) var inner by spec(innerSpec) } testObject.config["myValue"] = "theString" diff --git a/dataforge-output/build.gradle.kts b/dataforge-output/build.gradle.kts index ed0fa94e..6df39417 100644 --- a/dataforge-output/build.gradle.kts +++ b/dataforge-output/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } kotlin { diff --git a/dataforge-output/dataforge-output-html/build.gradle.kts b/dataforge-output/dataforge-output-html/build.gradle.kts index 3b5e24cb..292ed0ca 100644 --- a/dataforge-output/dataforge-output-html/build.gradle.kts +++ b/dataforge-output/dataforge-output-html/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } val htmlVersion by rootProject.extra("0.6.12") diff --git a/dataforge-scripting/build.gradle.kts b/dataforge-scripting/build.gradle.kts index 674ec25f..a1a65f97 100644 --- a/dataforge-scripting/build.gradle.kts +++ b/dataforge-scripting/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } kotlin { diff --git a/dataforge-workspace/build.gradle.kts b/dataforge-workspace/build.gradle.kts index cb2ce82c..8f5004b7 100644 --- a/dataforge-workspace/build.gradle.kts +++ b/dataforge-workspace/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") + `multiplatform-config` } kotlin { diff --git a/settings.gradle.kts b/settings.gradle.kts index fd01c861..03b9bff9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,7 +18,7 @@ pluginManagement { enableFeaturePreview("GRADLE_METADATA") -rootProject.name = "dataforge-core" +//rootProject.name = "dataforge-core" include( ":dataforge-meta", ":dataforge-io",