This commit is contained in:
Alexander Nozik 2020-05-04 19:57:27 +03:00
parent f2a5d0715c
commit 9e37d6f752
8 changed files with 144 additions and 103 deletions

View File

@ -3,11 +3,11 @@ import java.util.*
plugins {
`kotlin-dsl`
`maven-publish`
id("com.jfrog.bintray") version "1.8.4"
id("com.jfrog.bintray") version "1.8.5"
}
group = "scientifik"
version = "0.4.2"
version = "0.5.0"
repositories {
gradlePluginPortal()
@ -16,7 +16,7 @@ repositories {
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}
val kotlinVersion = "1.3.71"
val kotlinVersion = "1.3.72"
java {
targetCompatibility = JavaVersion.VERSION_1_8
@ -26,7 +26,7 @@ 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.2")
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.3")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.10.1")
}
@ -56,11 +56,11 @@ gradlePlugin {
implementationClass = "scientifik.ScientifikJSPlugin"
}
create("scientifik-atomic") {
id = "scientifik.atomic"
description = "Add kotlin atomic plugin to any flafor"
implementationClass = "scientifik.ScientifikAtomicPlugin"
}
// create("scientifik-atomic") {
// id = "scientifik.atomic"
// description = "Add kotlin atomic plugin to any flafor"
// implementationClass = "scientifik.ScientifikAtomicPlugin"
// }
}
}

View File

@ -2,6 +2,7 @@ package scientifik
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
@ -45,6 +46,9 @@ open class ScientifikJSPlugin : Plugin<Project> {
tasks.apply {
val processResources by getting(Copy::class)
processResources.copyJSResources(configurations["runtimeClasspath"])
val browserDistribution by getting {
doLast {
val indexFile = project.jsDistDirectory.resolve("index.html")

View File

@ -1,7 +1,6 @@
package scientifik
import Scientifik
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
@ -23,7 +22,7 @@ open class ScientifikJVMPlugin : Plugin<Project> {
repositories.applyRepos()
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = JavaVersion.VERSION_11
targetCompatibility = enumValueOf(Scientifik.JVM_VERSION)
}
tasks.withType<KotlinCompile> {

View File

@ -6,6 +6,7 @@ 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.*
@ -30,7 +31,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
}
}
js {
val js = js {
browser {
webpackTask {
outputFileName = "main.bundle.js"
@ -114,10 +115,9 @@ open class ScientifikMPPlugin : Plugin<Project> {
}
}
tasks.apply {
val jsProcessResources by getting(Copy::class)
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
val jsBrowserDistribution by getting {
doLast {
@ -128,6 +128,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
}
group = "distribution"
}
withType<Test>() {
useJUnitPlatform()
}

View File

@ -1,7 +1,10 @@
package scientifik
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
import java.io.File
@ -26,6 +29,36 @@ internal fun RepositoryHandler.applyRepos(): Unit {
maven("https://dl.bintray.com/mipt-npm/dataforge")
}
internal fun Copy.copyJSResources(configuration: Configuration): Unit = project.afterEvaluate {
val projectDeps = configuration
.allDependencies
.filterIsInstance<ProjectDependency>()
.map { it.dependencyProject }
val destination = destinationDir
projectDeps.forEach { dep ->
dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
dep.tasks.findByName("jsProcessResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
dep.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
dep.tasks.findByName("processResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
}
}
val Project.jsDistDirectory: File
get() {
val distributionName = listOf(

View File

@ -5,8 +5,6 @@ import kotlinx.atomicfu.plugin.gradle.sourceSets
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
enum class DependencyConfiguration {
@ -75,90 +73,7 @@ internal fun Project.useDependency(
}
}
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.serialization(
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
)
SerializationTargets(sourceSet, configuration).apply(block)
}
fun Project.coroutines(
fun Project.useCoroutines(
version: String = Scientifik.coroutinesVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API

View File

@ -46,12 +46,12 @@ fun KotlinDependencyHandler.addFXDependencies(
}
}
fun Project.fx(
fun Project.useFx(
vararg modules: FXModule,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "14",
platform: FXPlatform = defaultPlatform
) {
): Unit = afterEvaluate{
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
sourceSets.findByName("jvmMain")?.apply {

View File

@ -0,0 +1,89 @@
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
)
SerializationTargets(sourceSet, configuration).apply(block)
}