diff --git a/build.gradle.kts b/build.gradle.kts index afa849c6..a49a9e8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,226 +1,19 @@ -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") - - val dataforgeVersion: String by rootProject.extra("0.1.2-dev-4") - - 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.3-dev-1") allprojects { - apply(plugin = "maven") - apply(plugin = "maven-publish") - apply(plugin = "com.jfrog.artifactory") - repositories { jcenter() maven("https://kotlin.bintray.com/kotlinx") - maven("http://npm.mipt.ru:8081/artifactory/gradle-dev") - mavenLocal() + maven("http://npm.mipt.ru:8081/artifactory/gradle-dev-local") } group = "hep.dataforge" - version = "0.0.1-dev-1" - - // apply bintray configuration - apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") - - //apply artifactory configuration - apply(from = "${rootProject.rootDir}/gradle/artifactory.gradle") - + version = dataforgeVersion } subprojects { - - // dokka { -// outputFormat = "html" -// outputDirectory = javadoc.destinationDir +// apply(plugin = "dokka-publish") +// if (name.startsWith("dataforge")) { +// apply(plugin = "npm-publish") // } -// -// 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()) - } - } - } - } - } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..6f97d9c5 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() + jcenter() + maven("https://dl.bintray.com/kotlin/kotlin-eap") +} + +val kotlinVersion = "1.3.21" + +// 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.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") + implementation("org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.45") +} 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..883af120 --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,9 @@ +// 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 serializationVersion = "0.11.0" +} 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 00000000..b7b48fb6 --- /dev/null +++ b/buildSrc/src/main/kotlin/dokka-publish.gradle.kts @@ -0,0 +1,75 @@ +import org.jetbrains.dokka.gradle.DokkaTask +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/js-test.gradle.kts b/buildSrc/src/main/kotlin/js-test.gradle.kts new file mode 100644 index 00000000..9fa69aa0 --- /dev/null +++ b/buildSrc/src/main/kotlin/js-test.gradle.kts @@ -0,0 +1,43 @@ +import com.moowork.gradle.node.npm.NpmTask +import com.moowork.gradle.node.task.NodeTask +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/npm-multiplatform.gradle.kts b/buildSrc/src/main/kotlin/npm-multiplatform.gradle.kts new file mode 100644 index 00000000..dd048a39 --- /dev/null +++ b/buildSrc/src/main/kotlin/npm-multiplatform.gradle.kts @@ -0,0 +1,87 @@ +import org.gradle.kotlin.dsl.`maven-publish` +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.kotlin + +plugins { + kotlin("multiplatform") + `maven-publish` +} + + +kotlin { + jvm { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + js { + compilations.all { + kotlinOptions { + metaInfo = true + sourceMap = true + sourceMapEmbedSources = "always" + moduleKind = "commonjs" + } + } + + compilations.named("main") { + kotlinOptions { + main = "call" + } + } + } + + 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 + languageSettings.enableLanguageFeature("InlineClasses") + } + } + + // Apply JS test configuration + val runJsTests by ext(false) + + if (runJsTests) { + apply(plugin = "js-test") + } + +} 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..851348ba --- /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/altavir/dataforge-core" +val bintrayRepo = "https://bintray.com/mipt-npm/dataforge" + +// 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 = "dataforge" + 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/dataforge-vis-common/build.gradle.kts b/dataforge-vis-common/build.gradle.kts index 8e7aa82e..900391e9 100644 --- a/dataforge-vis-common/build.gradle.kts +++ b/dataforge-vis-common/build.gradle.kts @@ -1,30 +1,15 @@ plugins { - kotlin("multiplatform") + `npm-multiplatform` } val dataforgeVersion: String by rootProject.extra kotlin { - jvm() - js() - sourceSets { val commonMain by getting { dependencies { api("hep.dataforge:dataforge-output:$dataforgeVersion") - //api("hep.dataforge:dataforge-output-metadata:$dataforgeVersion") } } -// val jvmMain by getting { -// dependencies { -// api("hep.dataforge:dataforge-output-jvm:$dataforgeVersion") -// //api("no.tornado:tornadofx:1.7.18") -// } -// } -// val jsMain by getting { -// dependencies { -// api("hep.dataforge:dataforge-output-js:$dataforgeVersion") -// } -// } } } \ No newline at end of file diff --git a/dataforge-vis-spatial-js/build.gradle.kts b/dataforge-vis-spatial-js/build.gradle.kts index 1fccd801..14fe1ca4 100644 --- a/dataforge-vis-spatial-js/build.gradle.kts +++ b/dataforge-vis-spatial-js/build.gradle.kts @@ -1,6 +1,7 @@ import org.jetbrains.kotlin.gradle.frontend.KotlinFrontendExtension import org.jetbrains.kotlin.gradle.frontend.npm.NpmExtension import org.jetbrains.kotlin.gradle.frontend.webpack.WebPackExtension +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile plugins { id("kotlin2js") @@ -12,9 +13,9 @@ plugins { val kotlinVersion: String by rootProject.extra dependencies { - api(project(":dataforge-vis-spatial")) + implementation(project(":dataforge-vis-spatial")) implementation("info.laht.threekt:threejs-wrapper:0.88-npm-2") - testCompile("org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion") + testCompile("org.jetbrains.kotlin:kotlin-test-js:1.3.21") } configure { @@ -39,24 +40,24 @@ configure { } } -tasks{ - compileKotlin2Js{ - kotlinOptions{ +tasks { + "compileKotlin2Js"(Kotlin2JsCompile::class) { + kotlinOptions { metaInfo = true outputFile = "${project.buildDir.path}/js/${project.name}.js" sourceMap = true - moduleKind = "umd" + moduleKind = "commonjs" main = "call" kotlinOptions.sourceMapEmbedSources = "always" } } - compileTestKotlin2Js{ - kotlinOptions{ + "compileTestKotlin2Js"(Kotlin2JsCompile::class) { + kotlinOptions { metaInfo = true outputFile = "${project.buildDir.path}/js/${project.name}-test.js" sourceMap = true - moduleKind = "umd" + moduleKind = "commonjs" kotlinOptions.sourceMapEmbedSources = "always" } } diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index 5eb5a54c..73f33bac 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -1,27 +1,14 @@ plugins { - kotlin("multiplatform") + `npm-multiplatform` } kotlin { - jvm() - js() - sourceSets { val commonMain by getting { dependencies { api(project(":dataforge-vis-common")) } } - val jvmMain by getting { - dependencies { - - } - } - val jsMain by getting { - dependencies { - - } - } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 010f13f9..95d02740 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,6 +19,7 @@ pluginManagement { enableFeaturePreview("GRADLE_METADATA") rootProject.name = "dataforge-vis" + include( ":dataforge-vis-common", ":dataforge-vis-spatial",