Migrate to kScience and kotlin 1.4

This commit is contained in:
Alexander Nozik 2020-08-20 10:02:28 +03:00
parent 589ac77c2b
commit 6464d9d926
20 changed files with 340 additions and 310 deletions

View File

@ -7,8 +7,8 @@ plugins {
id("org.jetbrains.changelog") version "0.3.2" id("org.jetbrains.changelog") version "0.3.2"
} }
group = "scientifik" group = "ru.mipt.npm"
version = "0.5.2" version = "0.6.0"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
@ -17,7 +17,7 @@ repositories {
maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlin-eap")
} }
val kotlinVersion = "1.3.72" val kotlinVersion = "1.4.0"
java { java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -27,34 +27,47 @@ java {
dependencies { dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.3") implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.10.1") implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.0-rc")
implementation("org.jetbrains.dokka:dokka-core:1.4.0-rc")
} }
gradlePlugin { gradlePlugin {
plugins { plugins {
create("scientifik-publish") { create("kscience-publish") {
id = "scientifik.publish" id = "kscience.publish"
description = "The publication plugin for bintray and github" description = "The publication plugin for bintray and github"
implementationClass = "scientifik.ScientifikPublishPlugin" implementationClass = "ru.mipt.npm.gradle.KSciencePublishPlugin"
} }
create("scientifik-mpp") { create("kscience.mpp") {
id = "scientifik.mpp" id = "kscience.mpp"
description = "Pre-configured multiplatform project" description = "Pre-configured multiplatform project"
implementationClass = "scientifik.ScientifikMPPlugin" implementationClass = "ru.mipt.npm.gradle.KScienceMPPlugin"
} }
create("scientifik-jvm") { create("kscience.jvm") {
id = "scientifik.jvm" id = "kscience.jvm"
description = "Pre-configured JVM project" description = "Pre-configured JVM project"
implementationClass = "scientifik.ScientifikJVMPlugin" implementationClass = "ru.mipt.npm.gradle.KScienceJVMPlugin"
} }
create("scientifik-js") { create("kscience.js") {
id = "scientifik.js" id = "kscience.js"
description = "Pre-configured JS project" 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 // this is a problem of this plugin
pkg.apply { pkg.apply {
userOrg = "mipt-npm" 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 name = project.name
issueTrackerUrl = "$vcs/issues" issueTrackerUrl = "$vcs/issues"
setLicenses("Apache-2.0") setLicenses("Apache-2.0")

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

21
gradlew.bat vendored
View File

@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 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_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -64,21 +64,6 @@ echo location of your Java installation.
goto fail 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 :execute
@rem Setup the command line @rem Setup the command line
@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @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 :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

View File

@ -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"
}
}

View File

@ -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
}
}

View File

@ -1,4 +1,4 @@
package scientifik package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
@ -9,14 +9,16 @@ import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
open class ScientifikJSPlugin : Plugin<Project> { open class KScienceJSPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.js") plugins.apply("org.jetbrains.kotlin.js")
val extension = extensions.add("kscience", KScienceExtension(this))
repositories.applyRepos() repositories.applyRepos()
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
target { explicitApiWarning()
js(IR) {
browser { browser {
webpackTask { webpackTask {
outputFileName = "main.bundle.js" outputFileName = "main.bundle.js"
@ -47,18 +49,14 @@ open class ScientifikJSPlugin : Plugin<Project> {
val processResources by getting(Copy::class) val processResources by getting(Copy::class)
processResources.copyJSResources(configurations["runtimeClasspath"]) processResources.copyJSResources(configurations["runtimeClasspath"])
val browserDistribution by getting { findByName("jsBrowserDistribution")?.apply {
doLast { doLast {
val indexFile = project.jsDistDirectory.resolve("index.html") val indexFile = project.jsDistDirectory.resolve("index.html")
if (indexFile.exists()) { if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}") println("Run JS distribution at: ${indexFile.canonicalPath}")
} }
} }
group = "distribution"
} }
// findByName("assemble")?.dependsOn(installJsDist)
} }
} }

View File

@ -1,9 +1,7 @@
package scientifik package ru.mipt.npm.gradle
import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication 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.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
open class ScientifikJVMPlugin : Plugin<Project> { open class KScienceJVMPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.jvm") plugins.apply("org.jetbrains.kotlin.jvm")
val extension = extensions.add("kscience", KScienceExtension(this))
repositories.applyRepos() repositories.applyRepos()
extensions.findByType<JavaPluginExtension>()?.apply { extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = Scientifik.JVM_TARGET targetCompatibility = KScienceVersions.JVM_TARGET
} }
tasks.withType<KotlinCompile> { tasks.withType<KotlinCompile> {
kotlinOptions { kotlinOptions {
jvmTarget = Scientifik.JVM_TARGET.toString() useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
} }
} }
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
explicitApiWarning()
val sourceSet = sourceSets["main"].apply { val sourceSet = sourceSets["main"].apply {
languageSettings.applySettings() languageSettings.applySettings()
dependencies {
api(kotlin("stdlib-jdk8"))
}
} }
sourceSets["test"].apply { sourceSets["test"].apply {
languageSettings.applySettings() languageSettings.applySettings()
dependencies { dependencies {
implementation(kotlin("test"))
// implementation(kotlin("test-junit"))
implementation(kotlin("test-junit5")) implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1") implementation("org.junit.jupiter:junit-jupiter:5.6.1")
} }
@ -69,23 +64,10 @@ open class ScientifikJVMPlugin : Plugin<Project> {
pluginManager.withPlugin("org.jetbrains.dokka") { pluginManager.withPlugin("org.jetbrains.dokka") {
logger.info("Adding dokka functionality to project ${project.name}") logger.info("Adding dokka functionality to project ${project.name}")
val dokka by tasks.getting(DokkaTask::class) { val dokkaHtml by tasks.getting(DokkaTask::class){
outputFormat = "html" dokkaSourceSets {
outputDirectory = "$buildDir/javadoc" configureEach {
} jdkVersion = 11
val kdocJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
dependsOn(dokka)
archiveClassifier.set("javadoc")
from("$buildDir/javadoc")
}
configure<PublishingExtension> {
publications {
getByName("jvm") {
this as MavenPublication
artifact(kdocJar.get())
} }
} }
} }

View File

@ -1,36 +1,34 @@
package scientifik package ru.mipt.npm.gradle
import Scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project 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.Copy
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
open class ScientifikMPPlugin : Plugin<Project> { open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.multiplatform") plugins.apply("org.jetbrains.kotlin.multiplatform")
val extension = extensions.add("kscience", KScienceExtension(this))
repositories.applyRepos() repositories.applyRepos()
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
explicitApiWarning()
jvm { jvm {
compilations.all { compilations.all {
kotlinOptions { kotlinOptions {
jvmTarget = Scientifik.JVM_TARGET.toString() useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
} }
} }
} }
val js = js { js(IR) {
browser { browser {
webpackTask { webpackTask {
outputFileName = "main.bundle.js" outputFileName = "main.bundle.js"
@ -42,35 +40,21 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
sourceSets.invoke { sourceSets.invoke {
val commonMain by getting { val commonMain by getting
dependencies {
api(kotlin("stdlib"))
}
}
val commonTest by getting { val commonTest by getting {
dependencies { dependencies {
implementation(kotlin("test-common")) implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common")) implementation(kotlin("test-annotations-common"))
} }
} }
val jvmMain by getting { val jvmMain by getting
dependencies {
api(kotlin("stdlib-jdk8"))
}
}
val jvmTest by getting { val jvmTest by getting {
dependencies { dependencies {
implementation(kotlin("test"))
// implementation(kotlin("test-junit"))
implementation(kotlin("test-junit5")) implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1") implementation("org.junit.jupiter:junit-jupiter:5.6.1")
} }
} }
val jsMain by getting { val jsMain by getting
dependencies {
api(kotlin("stdlib-js"))
}
}
val jsTest by getting { val jsTest by getting {
dependencies { dependencies {
implementation(kotlin("test-js")) implementation(kotlin("test-js"))
@ -86,29 +70,11 @@ open class ScientifikMPPlugin : Plugin<Project> {
pluginManager.withPlugin("org.jetbrains.dokka") { pluginManager.withPlugin("org.jetbrains.dokka") {
logger.info("Adding dokka functionality to project ${this@run.name}") logger.info("Adding dokka functionality to project ${this@run.name}")
val dokka by tasks.getting(DokkaTask::class) {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
multiplatform {
} val dokkaHtml by tasks.getting(DokkaTask::class) {
} dokkaSourceSets {
configureEach {
val kdocJar by tasks.registering(Jar::class) { jdkVersion = 11
group = JavaBasePlugin.DOCUMENTATION_GROUP
dependsOn(dokka)
archiveClassifier.set("javadoc")
from("$buildDir/javadoc")
}
pluginManager.withPlugin("maven-publish") {
configure<PublishingExtension> {
targets.all {
val publication = publications.findByName(name) as MavenPublication
// Patch publications with fake javadoc
publication.artifact(kdocJar.get())
} }
} }
} }
@ -125,14 +91,13 @@ open class ScientifikMPPlugin : Plugin<Project> {
val jvmProcessResources by getting(Copy::class) val jvmProcessResources by getting(Copy::class)
jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"]) jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"])
val jsBrowserDistribution by getting { findByName("jsBrowserDistribution")?.apply {
doLast { doLast {
val indexFile = project.jsDistDirectory.resolve("index.html") val indexFile = project.jsDistDirectory.resolve("index.html")
if (indexFile.exists()) { if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}") println("Run JS distribution at: ${indexFile.canonicalPath}")
} }
} }
group = "distribution"
} }
} }

View File

@ -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<Project> {
override fun apply(target: Project) = target.run {
if (plugins.findPlugin(KScienceMPPlugin::class) == null) {
pluginManager.apply(KScienceMPPlugin::class)
}
configure<KotlinMultiplatformExtension> {
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
// }
}
}
}

View File

@ -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<Project> {
override fun apply(target: Project) = target.run{
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
js {
nodejs()
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure<KotlinJsProjectExtension> {
js {
nodejs()
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package scientifik package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
@ -9,16 +9,17 @@ import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType import org.gradle.kotlin.dsl.withType
open class ScientifikPublishPlugin : Plugin<Project> { open class KSciencePublishPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
project.plugins.apply("maven-publish") project.plugins.apply("maven-publish")
project.afterEvaluate { 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 val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/mipt-npm/$it" } ?: githubProject?.let { "https://github.com/$githubOrg/$it" }
if (vcs == null) { if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
@ -95,8 +96,8 @@ open class ScientifikPublishPlugin : Plugin<Project> {
} }
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser = project.findProperty("bintrayUser") as? String val bintrayUser: String? by project
val bintrayKey = project.findProperty("bintrayApiKey") as? String val bintrayApiKey: String? by project
val bintrayRepo = if (project.version.toString().contains("dev")) { val bintrayRepo = if (project.version.toString().contains("dev")) {
@ -107,7 +108,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
val projectName = project.name 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]") project.logger.info("Adding bintray publishing to project [$projectName]")
repositories { repositories {
@ -118,7 +119,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
) )
credentials { credentials {
username = bintrayUser username = bintrayUser
password = bintrayKey password = bintrayApiKey
} }
} }
} }

View File

@ -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"
}
}

View File

@ -1,4 +1,4 @@
package scientifik package ru.mipt.npm.gradle
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
@ -23,9 +23,10 @@ internal fun RepositoryHandler.applyRepos(): Unit {
jcenter() jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx") 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://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") maven("https://dl.bintray.com/mipt-npm/dataforge")
} }

View File

@ -1,6 +1,5 @@
package scientifik package ru.mipt.npm.gradle
import Scientifik
import kotlinx.atomicfu.plugin.gradle.sourceSets import kotlinx.atomicfu.plugin.gradle.sourceSets
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.findByType
@ -73,25 +72,46 @@ internal fun Project.useDependency(
} }
} }
fun Project.useCoroutines( internal fun Project.useCommonDependency(
version: String = Scientifik.coroutinesVersion, dep: String,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION
) = useDependency( ): Unit = pluginManager.run{
"common" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version", withPlugin("org.jetbrains.kotlin.multiplatform"){
"jvm" to "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version", extensions.findByType<KotlinMultiplatformExtension>()?.apply {
"js" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$version", sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply {
"native" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$version", dependencies {
dependencySourceSet = sourceSet, when (dependencyConfiguration) {
dependencyConfiguration = configuration DependencyConfiguration.API -> api(dep)
) DependencyConfiguration.IMPLEMENTATION -> implementation(dep)
DependencyConfiguration.COMPILE_ONLY -> compileOnly(dep)
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", withPlugin("org.jetbrains.kotlin.jvm") {
"nativeMain" to "org.jetbrains.kotlinx:atomicfu-native:$version" 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)
}
}
}
} }

View File

@ -1,4 +1,4 @@
package scientifik package ru.mipt.npm.gradle
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project import org.gradle.api.Project

View File

@ -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
)
}
}

View File

@ -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<Project> {
override fun apply(target: Project) {
target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
target.configure<KotlinMultiplatformExtension> {
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)
}
}
}
}
}
}

View File

@ -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)
}