diff --git a/build.gradle.kts b/build.gradle.kts index 4275de1..51bfc16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,8 +7,8 @@ plugins { id("org.jetbrains.changelog") version "0.3.2" } -group = "scientifik" -version = "0.5.2" +group = "ru.mipt.npm" +version = "0.6.0" repositories { gradlePluginPortal() @@ -17,7 +17,7 @@ repositories { maven("https://dl.bintray.com/kotlin/kotlin-eap") } -val kotlinVersion = "1.3.72" +val kotlinVersion = "1.4.0" java { targetCompatibility = JavaVersion.VERSION_1_8 @@ -27,34 +27,47 @@ java { dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") - implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.3") - implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.10.1") + implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.0-rc") + implementation("org.jetbrains.dokka:dokka-core:1.4.0-rc") } gradlePlugin { plugins { - create("scientifik-publish") { - id = "scientifik.publish" + create("kscience-publish") { + id = "kscience.publish" description = "The publication plugin for bintray and github" - implementationClass = "scientifik.ScientifikPublishPlugin" + implementationClass = "ru.mipt.npm.gradle.KSciencePublishPlugin" } - create("scientifik-mpp") { - id = "scientifik.mpp" + create("kscience.mpp") { + id = "kscience.mpp" description = "Pre-configured multiplatform project" - implementationClass = "scientifik.ScientifikMPPlugin" + implementationClass = "ru.mipt.npm.gradle.KScienceMPPlugin" } - create("scientifik-jvm") { - id = "scientifik.jvm" + create("kscience.jvm") { + id = "kscience.jvm" description = "Pre-configured JVM project" - implementationClass = "scientifik.ScientifikJVMPlugin" + implementationClass = "ru.mipt.npm.gradle.KScienceJVMPlugin" } - create("scientifik-js") { - id = "scientifik.js" + create("kscience.js") { + id = "kscience.js" description = "Pre-configured JS project" - implementationClass = "scientifik.ScientifikJSPlugin" + implementationClass = "ru.mipt.npm.gradle.KScienceJSPlugin" + } + + create("kscience.native") { + id = "kscience.native" + description = "Additional native targets to be use alongside mpp" + implementationClass = "ru.mipt.npm.gradle.KScienceNativePlugin" + } + + create("kscience.node") { + id = "kscience.node" + description = "NodeJS target for kotlin-mpp and kotlin-js" + implementationClass = "ru.mipt.npm.gradle.KScienceNodePlugin" } } } @@ -106,7 +119,7 @@ publishing { // this is a problem of this plugin pkg.apply { userOrg = "mipt-npm" - repo = if (project.version.toString().contains("dev")) "dev" else "scientifik" + repo = if (project.version.toString().contains("dev")) "dev" else "kscience" name = project.name issueTrackerUrl = "$vcs/issues" setLicenses("Apache-2.0") diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c05..e708b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..6c9a224 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c51..4f906e0 100644 --- a/gradlew +++ b/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 5093609..107acd3 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/kotlin/Scientifik.kt b/src/main/kotlin/Scientifik.kt deleted file mode 100644 index 31b9450..0000000 --- a/src/main/kotlin/Scientifik.kt +++ /dev/null @@ -1,18 +0,0 @@ -import org.gradle.api.JavaVersion - -/** - * Build constants - */ -object Scientifik { - const val coroutinesVersion = "1.3.7" - const val serializationVersion = "0.20.0" - const val atomicVersion = "0.14.3" - - val JVM_TARGET = JavaVersion.VERSION_1_8 - - object Serialization{ - const val xmlVersion = "0.20.0.1" - const val yamlVersion = "0.16.1" - const val bsonVersion = "0.2.1" - } -} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt new file mode 100644 index 0000000..c801afd --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -0,0 +1,65 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.extra +import org.gradle.kotlin.dsl.findPlugin +import org.gradle.kotlin.dsl.provideDelegate + +class KScienceExtension(val project: Project) { + + fun useCoroutines( + version: String = KScienceVersions.coroutinesVersion, + sourceSet: DependencySourceSet = DependencySourceSet.MAIN, + configuration: DependencyConfiguration = DependencyConfiguration.API + ): Unit = project.useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + + fun useAtomic(version: String = KScienceVersions.atomicVersion): Unit = project.run { + plugins.apply("kotlinx-atomicfu") + useCommonDependency( + "org.jetbrains.kotlinx:atomicfu:$version" + ) + } + + fun useSerialization( + version: String = KScienceVersions.serializationVersion, + sourceSet: DependencySourceSet = DependencySourceSet.MAIN, + configuration: DependencyConfiguration = DependencyConfiguration.API, + block: SerializationTargets.() -> Unit = {} + ): Unit = project.run { + plugins.apply("org.jetbrains.kotlin.plugin.serialization") + useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-core:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + SerializationTargets(sourceSet, configuration).apply(block) + } + + /** + * Activate publishing and configure it + */ + fun publishing(block: Publishing.() -> Unit) = Publishing().apply(block) + + inner class Publishing { + init { + if (project.plugins.findPlugin(KSciencePublishPlugin::class) == null) { + project.plugins.apply(KSciencePublishPlugin::class) + } + } + + var githubOrg: String? by project.extra + var githubProject: String? by project.extra + var spaceRepo: String? by project.extra + var spaceUser: String? by project.extra + var spaceToken: String? by project.extra + var bintrayOrg: String? by project.extra + var bintrayUser: String? by project.extra + var bintrayApiKey: String? by project.extra + var bintrayRepo: String? by project.extra + } +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt similarity index 86% rename from src/main/kotlin/scientifik/ScientifikJSPlugin.kt rename to src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index 234b5eb..0813c27 100644 --- a/src/main/kotlin/scientifik/ScientifikJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -1,4 +1,4 @@ -package scientifik +package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project @@ -9,14 +9,16 @@ import org.gradle.kotlin.dsl.getValue import org.gradle.kotlin.dsl.getting import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension -open class ScientifikJSPlugin : Plugin { +open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.js") + val extension = extensions.add("kscience", KScienceExtension(this)) repositories.applyRepos() configure { - target { + explicitApiWarning() + js(IR) { browser { webpackTask { outputFileName = "main.bundle.js" @@ -47,18 +49,14 @@ open class ScientifikJSPlugin : Plugin { val processResources by getting(Copy::class) processResources.copyJSResources(configurations["runtimeClasspath"]) - val browserDistribution by getting { + findByName("jsBrowserDistribution")?.apply { doLast { val indexFile = project.jsDistDirectory.resolve("index.html") if (indexFile.exists()) { println("Run JS distribution at: ${indexFile.canonicalPath}") } } - group = "distribution" } - -// findByName("assemble")?.dependsOn(installJsDist) - } } diff --git a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt similarity index 66% rename from src/main/kotlin/scientifik/ScientifikJVMPlugin.kt rename to src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index 64b407e..697361b 100644 --- a/src/main/kotlin/scientifik/ScientifikJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -1,9 +1,7 @@ -package scientifik +package ru.mipt.npm.gradle -import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -15,36 +13,33 @@ import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -open class ScientifikJVMPlugin : Plugin { +open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.jvm") + val extension = extensions.add("kscience", KScienceExtension(this)) repositories.applyRepos() extensions.findByType()?.apply { - targetCompatibility = Scientifik.JVM_TARGET + targetCompatibility = KScienceVersions.JVM_TARGET } tasks.withType { kotlinOptions { - jvmTarget = Scientifik.JVM_TARGET.toString() + useIR = true + jvmTarget = KScienceVersions.JVM_TARGET.toString() } } configure { - + explicitApiWarning() val sourceSet = sourceSets["main"].apply { languageSettings.applySettings() - dependencies { - api(kotlin("stdlib-jdk8")) - } } sourceSets["test"].apply { languageSettings.applySettings() dependencies { - implementation(kotlin("test")) -// implementation(kotlin("test-junit")) implementation(kotlin("test-junit5")) implementation("org.junit.jupiter:junit-jupiter:5.6.1") } @@ -69,23 +64,10 @@ open class ScientifikJVMPlugin : Plugin { pluginManager.withPlugin("org.jetbrains.dokka") { logger.info("Adding dokka functionality to project ${project.name}") - val dokka by tasks.getting(DokkaTask::class) { - outputFormat = "html" - outputDirectory = "$buildDir/javadoc" - } - - val kdocJar by tasks.registering(Jar::class) { - group = JavaBasePlugin.DOCUMENTATION_GROUP - dependsOn(dokka) - archiveClassifier.set("javadoc") - from("$buildDir/javadoc") - } - - configure { - publications { - getByName("jvm") { - this as MavenPublication - artifact(kdocJar.get()) + val dokkaHtml by tasks.getting(DokkaTask::class){ + dokkaSourceSets { + configureEach { + jdkVersion = 11 } } } diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt similarity index 58% rename from src/main/kotlin/scientifik/ScientifikMPPlugin.kt rename to src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index d72bf69..87b39db 100644 --- a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -1,36 +1,34 @@ -package scientifik +package ru.mipt.npm.gradle -import Scientifik import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.plugins.JavaBasePlugin -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.* import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -open class ScientifikMPPlugin : Plugin { +open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { plugins.apply("org.jetbrains.kotlin.multiplatform") + val extension = extensions.add("kscience", KScienceExtension(this)) repositories.applyRepos() configure { + explicitApiWarning() jvm { compilations.all { kotlinOptions { - jvmTarget = Scientifik.JVM_TARGET.toString() + useIR = true + jvmTarget = KScienceVersions.JVM_TARGET.toString() } } } - val js = js { + js(IR) { browser { webpackTask { outputFileName = "main.bundle.js" @@ -42,35 +40,21 @@ open class ScientifikMPPlugin : Plugin { } sourceSets.invoke { - val commonMain by getting { - dependencies { - api(kotlin("stdlib")) - } - } + val commonMain by getting val commonTest by getting { dependencies { implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) } } - val jvmMain by getting { - dependencies { - api(kotlin("stdlib-jdk8")) - } - } + val jvmMain by getting val jvmTest by getting { dependencies { - implementation(kotlin("test")) -// implementation(kotlin("test-junit")) implementation(kotlin("test-junit5")) implementation("org.junit.jupiter:junit-jupiter:5.6.1") } } - val jsMain by getting { - dependencies { - api(kotlin("stdlib-js")) - } - } + val jsMain by getting val jsTest by getting { dependencies { implementation(kotlin("test-js")) @@ -86,29 +70,11 @@ open class ScientifikMPPlugin : Plugin { pluginManager.withPlugin("org.jetbrains.dokka") { logger.info("Adding dokka functionality to project ${this@run.name}") - val dokka by tasks.getting(DokkaTask::class) { - outputFormat = "html" - outputDirectory = "$buildDir/javadoc" - multiplatform { - } - } - - val kdocJar by tasks.registering(Jar::class) { - group = JavaBasePlugin.DOCUMENTATION_GROUP - dependsOn(dokka) - archiveClassifier.set("javadoc") - from("$buildDir/javadoc") - } - - pluginManager.withPlugin("maven-publish") { - configure { - - targets.all { - val publication = publications.findByName(name) as MavenPublication - - // Patch publications with fake javadoc - publication.artifact(kdocJar.get()) + val dokkaHtml by tasks.getting(DokkaTask::class) { + dokkaSourceSets { + configureEach { + jdkVersion = 11 } } } @@ -125,14 +91,13 @@ open class ScientifikMPPlugin : Plugin { val jvmProcessResources by getting(Copy::class) jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"]) - val jsBrowserDistribution by getting { + findByName("jsBrowserDistribution")?.apply { doLast { val indexFile = project.jsDistDirectory.resolve("index.html") if (indexFile.exists()) { println("Run JS distribution at: ${indexFile.canonicalPath}") } } - group = "distribution" } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt new file mode 100644 index 0000000..62be06f --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -0,0 +1,33 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.GradleException +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.findPlugin +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +class KScienceNativePlugin : Plugin { + override fun apply(target: Project) = target.run { + if (plugins.findPlugin(KScienceMPPlugin::class) == null) { + pluginManager.apply(KScienceMPPlugin::class) + } + configure { + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + + val nativeTarget = when { + hostOs == "Mac OS X" -> macosX64("native") + hostOs == "Linux" -> linuxX64("native") + isMingwX64 -> mingwX64("native") + else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + } +// +// sourceSets { +// val nativeMain by getting +// val nativeTest by getting +// } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt new file mode 100644 index 0000000..bba5346 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -0,0 +1,28 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +class KScienceNodePlugin : Plugin { + override fun apply(target: Project) = target.run{ + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + configure { + js { + nodejs() + } + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + configure { + js { + nodejs() + } + } + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt similarity index 90% rename from src/main/kotlin/scientifik/ScientifikPublishPlugin.kt rename to src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt index 3860570..9c4dad2 100644 --- a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt @@ -1,4 +1,4 @@ -package scientifik +package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project @@ -9,16 +9,17 @@ import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType -open class ScientifikPublishPlugin : Plugin { +open class KSciencePublishPlugin : Plugin { override fun apply(project: Project) { project.plugins.apply("maven-publish") project.afterEvaluate { - val githubProject = findProperty("githubProject") as? String + val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" + val githubProject: String? by project val vcs = findProperty("vcs") as? String - ?: githubProject?.let { "https://github.com/mipt-npm/$it" } + ?: githubProject?.let { "https://github.com/$githubOrg/$it" } if (vcs == null) { project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") @@ -95,8 +96,8 @@ open class ScientifikPublishPlugin : Plugin { } val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" - val bintrayUser = project.findProperty("bintrayUser") as? String - val bintrayKey = project.findProperty("bintrayApiKey") as? String + val bintrayUser: String? by project + val bintrayApiKey: String? by project val bintrayRepo = if (project.version.toString().contains("dev")) { @@ -107,7 +108,7 @@ open class ScientifikPublishPlugin : Plugin { val projectName = project.name - if (bintrayRepo != null && bintrayUser != null && bintrayKey != null) { + if (bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) { project.logger.info("Adding bintray publishing to project [$projectName]") repositories { @@ -118,7 +119,7 @@ open class ScientifikPublishPlugin : Plugin { ) credentials { username = bintrayUser - password = bintrayKey + password = bintrayApiKey } } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt new file mode 100644 index 0000000..aef8579 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -0,0 +1,20 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.JavaVersion + +/** + * Build constants + */ +object KScienceVersions { + const val coroutinesVersion = "1.3.9" + const val serializationVersion = "1.0.0-RC" + const val atomicVersion = "0.14.4" + + val JVM_TARGET = JavaVersion.VERSION_11 + + object Serialization{ + const val xmlVersion = "0.20.0.1" + const val yamlVersion = "0.16.1" + const val bsonVersion = "0.2.1" + } +} diff --git a/src/main/kotlin/scientifik/common.kt b/src/main/kotlin/ru/mipt/npm/gradle/common.kt similarity index 97% rename from src/main/kotlin/scientifik/common.kt rename to src/main/kotlin/ru/mipt/npm/gradle/common.kt index 99eace0..1bb9213 100644 --- a/src/main/kotlin/scientifik/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/common.kt @@ -1,4 +1,4 @@ -package scientifik +package ru.mipt.npm.gradle import org.gradle.api.Project import org.gradle.api.artifacts.Configuration @@ -23,9 +23,10 @@ internal fun RepositoryHandler.applyRepos(): Unit { jcenter() maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://kotlin.bintray.com/kotlinx") - maven("https://dl.bintray.com/mipt-npm/scientifik") - maven("https://dl.bintray.com/mipt-npm/dev") maven("https://kotlin.bintray.com/kotlin-js-wrappers/") + maven("https://dl.bintray.com/mipt-npm/scientifik") + maven("https://dl.bintray.com/mipt-npm/kscience") + maven("https://dl.bintray.com/mipt-npm/dev") maven("https://dl.bintray.com/mipt-npm/dataforge") } diff --git a/src/main/kotlin/scientifik/extensions.kt b/src/main/kotlin/ru/mipt/npm/gradle/extensions.kt similarity index 54% rename from src/main/kotlin/scientifik/extensions.kt rename to src/main/kotlin/ru/mipt/npm/gradle/extensions.kt index 002f397..4dcea9b 100644 --- a/src/main/kotlin/scientifik/extensions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/extensions.kt @@ -1,6 +1,5 @@ -package scientifik +package ru.mipt.npm.gradle -import Scientifik import kotlinx.atomicfu.plugin.gradle.sourceSets import org.gradle.api.Project import org.gradle.kotlin.dsl.findByType @@ -33,7 +32,7 @@ internal fun Project.useDependency( when (dependencyConfiguration) { DependencyConfiguration.API -> api(dep) DependencyConfiguration.IMPLEMENTATION -> implementation(dep) - DependencyConfiguration.COMPILE_ONLY-> compileOnly(dep) + DependencyConfiguration.COMPILE_ONLY -> compileOnly(dep) } } } @@ -49,7 +48,7 @@ internal fun Project.useDependency( val configurationName = when (dependencyConfiguration) { DependencyConfiguration.API -> apiConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY-> compileOnlyConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName } add(configurationName, dep.second) } @@ -64,7 +63,7 @@ internal fun Project.useDependency( val configurationName = when (dependencyConfiguration) { DependencyConfiguration.API -> apiConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY-> compileOnlyConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName } add(configurationName, dep.second) } @@ -73,25 +72,46 @@ internal fun Project.useDependency( } } -fun Project.useCoroutines( - version: String = Scientifik.coroutinesVersion, - sourceSet: DependencySourceSet = DependencySourceSet.MAIN, - configuration: DependencyConfiguration = DependencyConfiguration.API -) = useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration -) - -fun Project.useAtomic(version: String = Scientifik.atomicVersion) { - plugins.apply("kotlinx-atomicfu") - useDependency( - "commonMain" to "org.jetbrains.kotlinx:atomicfu-common:$version", - "jvmMain" to "org.jetbrains.kotlinx:atomicfu:$version", - "jsMain" to "org.jetbrains.kotlinx:atomicfu-js:$version", - "nativeMain" to "org.jetbrains.kotlinx:atomicfu-native:$version" - ) -} +internal fun Project.useCommonDependency( + dep: String, + dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN, + dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION +): Unit = pluginManager.run{ + withPlugin("org.jetbrains.kotlin.multiplatform"){ + extensions.findByType()?.apply { + sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply { + dependencies { + when (dependencyConfiguration) { + DependencyConfiguration.API -> api(dep) + DependencyConfiguration.IMPLEMENTATION -> implementation(dep) + DependencyConfiguration.COMPILE_ONLY -> compileOnly(dep) + } + } + } + } + } + withPlugin("org.jetbrains.kotlin.jvm") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep) + } + } + } + withPlugin("org.jetbrains.kotlin.js") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/fx.kt b/src/main/kotlin/ru/mipt/npm/gradle/fx.kt similarity index 98% rename from src/main/kotlin/scientifik/fx.kt rename to src/main/kotlin/ru/mipt/npm/gradle/fx.kt index 7faaed1..76f30c0 100644 --- a/src/main/kotlin/scientifik/fx.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/fx.kt @@ -1,4 +1,4 @@ -package scientifik +package ru.mipt.npm.gradle import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.Project diff --git a/src/main/kotlin/ru/mipt/npm/gradle/serialization.kt b/src/main/kotlin/ru/mipt/npm/gradle/serialization.kt new file mode 100644 index 0000000..a5eb039 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/serialization.kt @@ -0,0 +1,65 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Project +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.repositories + +class SerializationTargets( + val sourceSet: DependencySourceSet, + val configuration: DependencyConfiguration +) { + fun Project.cbor( + version: String = KScienceVersions.serializationVersion + ) { + useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.protobuf( + version: String = KScienceVersions.serializationVersion + ) { + useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.xml( + version: String = KScienceVersions.Serialization.xmlVersion + ) { + repositories { + maven("https://dl.bintray.com/pdvrieze/maven") + } + useDependency( + "common" to "net.devrieze:xmlutil-serialization:$version", + "jvm" to "net.devrieze:xmlutil-serialization:$version", + "js" to "net.devrieze:xmlutil-serialization:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.yaml( + version: String = KScienceVersions.Serialization.yamlVersion + ) { + useDependency( + "jvm" to "com.charleskorn.kaml:kaml:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } + + fun Project.bson( + version: String = KScienceVersions.Serialization.bsonVersion + ) { + useDependency( + "jvm" to "com.github.jershell:kbson:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) + } +} diff --git a/src/main/kotlin/scientifik/ScientifikNativePlugin.kt b/src/main/kotlin/scientifik/ScientifikNativePlugin.kt deleted file mode 100644 index 95b4d45..0000000 --- a/src/main/kotlin/scientifik/ScientifikNativePlugin.kt +++ /dev/null @@ -1,38 +0,0 @@ -package scientifik - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.* -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension - -class ScientifikNativePlugin : Plugin { - override fun apply(target: Project) { - target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - target.configure { - linuxX64() - mingwX64() - - sourceSets.apply { - val commonMain by getting {} - - val native by creating { - dependsOn(commonMain) - - dependencies { - api(kotlin("native")) - //TODO add stdlib here - } - } - - mingwX64().compilations["main"].defaultSourceSet { - dependsOn(native) - } - - linuxX64().compilations["main"].defaultSourceSet { - dependsOn(native) - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/serialization.kt b/src/main/kotlin/scientifik/serialization.kt deleted file mode 100644 index 3671512..0000000 --- a/src/main/kotlin/scientifik/serialization.kt +++ /dev/null @@ -1,90 +0,0 @@ -package scientifik - -import Scientifik -import org.gradle.api.Project -import org.gradle.kotlin.dsl.maven -import org.gradle.kotlin.dsl.repositories - -class SerializationTargets( - val sourceSet: DependencySourceSet, - val configuration: DependencyConfiguration -) { - fun Project.cbor( - version: String = Scientifik.serializationVersion - ) { - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.protobuf( - version: String = Scientifik.serializationVersion - ) { - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.xml( - version: String = Scientifik.Serialization.xmlVersion - ) { - repositories { - maven("https://dl.bintray.com/pdvrieze/maven") - } - useDependency( - "common" to "net.devrieze:xmlutil-serialization:$version", - "jvm" to "net.devrieze:xmlutil-serialization:$version", - "js" to "net.devrieze:xmlutil-serialization:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.yaml( - version: String = Scientifik.Serialization.yamlVersion - ) { - useDependency( - "jvm" to "com.charleskorn.kaml:kaml:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.bson( - version: String = Scientifik.Serialization.bsonVersion - ) { - useDependency( - "jvm" to "com.github.jershell:kbson:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } -} - -fun Project.useSerialization( - version: String = Scientifik.serializationVersion, - sourceSet: DependencySourceSet = DependencySourceSet.MAIN, - configuration: DependencyConfiguration = DependencyConfiguration.API, - block: SerializationTargets.() -> Unit = {} -) { - plugins.apply("org.jetbrains.kotlin.plugin.serialization") - useDependency( - "common" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$version", - "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version", - "js" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$version", - "native" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - SerializationTargets(sourceSet, configuration).apply(block) -} \ No newline at end of file