From d6a9a58dc9483aa83a8f21b9787b0592e7d670c8 Mon Sep 17 00:00:00 2001 From: Adam <897017+asemy@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:30:06 +0100 Subject: [PATCH] kotlin 1.6, gradle tidying --- README.md | 11 ++- buildSrc/build.gradle.kts | 32 +------- buildSrc/repositories.settings.gradle.kts | 45 +++++++++++ buildSrc/settings.gradle.kts | 42 +--------- .../archetype/kotlin-js.gradle.kts | 2 +- .../archetype/kotlin-jvm.gradle.kts | 5 +- .../gradle/json-kotlin-schema-gen.gradle.kts | 12 --- .../dev/adamko/gradle/tstl/TstlPlugin.kt | 24 ------ .../gradle/tstl/tasks/TypescriptToLuaTask.kt | 50 ------------ gradle/libs.versions.toml | 8 +- .../build.gradle.kts | 79 +------------------ .../factorioevents/model/factorioEvents.kt | 12 +-- modules/mod/build.gradle.kts | 1 - settings.gradle.kts | 46 +---------- 14 files changed, 74 insertions(+), 295 deletions(-) create mode 100644 buildSrc/repositories.settings.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/dev/adamko/gradle/json-kotlin-schema-gen.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/TstlPlugin.kt delete mode 100644 buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/tasks/TypescriptToLuaTask.kt diff --git a/README.md b/README.md index 62bc90c..2a938cb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ 1. converts data to images 2. hosts a web map -todo +## todo * add settings * is active - whether files are exported or not @@ -15,7 +15,7 @@ todo * requires on some sort of in-mod cache of map) * also divide by game-speed? to keep ratio the same -to investigate: +### to investigate: * https://github.com/starwing/lua-protobuf * https://github.com/grafi-tt/lunajson @@ -28,4 +28,9 @@ to investigate: * https://opensource.expediagroup.com/graphql-kotlin/docs/server/spring-server/spring-subscriptions * https://github.com/YousefED/typescript-json-schema -* https://jbrandhorst.com/post/go-protobuf-tips/ \ No newline at end of file +* https://jbrandhorst.com/post/go-protobuf-tips/ + +#### CBOR + +https://www.zash.se/lua-cbor.html +https://code.zash.se/lua-cbor/archive/68b3a36d0816.tar.gz \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index f07747a..5e0c6e6 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,35 +3,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { idea `kotlin-dsl` - kotlin("jvm") version "1.5.31" + kotlin("jvm") version "1.6.0" `java-gradle-plugin` } -gradlePlugin { - plugins { - create("tstl") { - id = "dev.adamko.tstl" - description = - "Gradle plugin for TypescriptToLua. Requires plugin `com.github.node-gradle.node`." - implementationClass = "dev.adamko.gradle.tstl.TstlPlugin" - } - create("json-kotlin-schema-gen") { - id = "dev.adamko.json-kotlin-schema-gen" - description = - "Gradle plugin for 'json-kotlin-schema-codegen' - Code generation for JSON Schema (Draft 07) https://github.com/pwall567/json-kotlin-schema-codegen" - implementationClass = "dev.adamko.gradle.jsonkotlinschemagen.JsonKotlinSchemaGenPlugin" - } - } -} - dependencies { - val kotlinVersion = "1.5.31" - -// implementation(gradleApi()) - -// implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:${org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion}") -// implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:${kotlinVersion}") + val kotlinVersion = "1.6.0" implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlinVersion")) implementation("org.jetbrains.kotlin:kotlin-serialization") @@ -39,8 +17,6 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin") implementation("com.github.node-gradle:gradle-node-plugin:3.1.1") - - implementation("net.pwall.json:json-kotlin-schema-codegen:0.53") } val projectJvmTarget = "11" @@ -49,8 +25,8 @@ tasks.withType().configureEach { kotlinOptions { jvmTarget = projectJvmTarget - apiVersion = "1.5" - languageVersion = "1.5" + apiVersion = "1.6" + languageVersion = "1.6" } kotlinOptions.freeCompilerArgs += listOf( diff --git a/buildSrc/repositories.settings.gradle.kts b/buildSrc/repositories.settings.gradle.kts new file mode 100644 index 0000000..550a6d5 --- /dev/null +++ b/buildSrc/repositories.settings.gradle.kts @@ -0,0 +1,45 @@ + +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { + + // https://github.com/gradle/gradle/issues/15754#issuecomment-763614651 + // https://github.com/gradle/gradle/blob/09fcaacc9848f09aa584b4119be9271bee6916e6/build-logic/build-logic-base/settings-plugin/src/main/kotlin/gradlebuild.repositories.settings.gradle.kts#L68 + + // Cannot use 'FAIL_ON_PROJECT_REPOS' because + // - the 'gradle-guides-plugin' adds a repo (which it should not do) + // - the 'kotlin-gradle-plugin' adds a repo (and removes it afterwards) to download NodeJS + repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) + + repositories { + mavenCentral() + gradlePluginPortal() + maven("https://jitpack.io") + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") + maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") + + // Declare the Node.js download repository + ivy("https://nodejs.org/dist/") { + name = "Node Distributions at $url" + patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") } + metadataSources { artifact() } + content { includeModule("org.nodejs", "node") } + } + ivy("https://github.com/yarnpkg/yarn/releases/download") { + name = "Yarn Distributions at $url" + patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") } + metadataSources { artifact() } + content { includeModule("com.yarnpkg", "yarn") } + } + } + + pluginManagement { + + repositories { + mavenCentral() + gradlePluginPortal() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") + } + + } + +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 3080aa2..8065bb4 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,43 +1,3 @@ rootProject.name = "buildSrc" -enableFeaturePreview("VERSION_CATALOGS") -enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") - -@Suppress("UnstableApiUsage") -dependencyResolutionManagement { - - repositories { - mavenCentral() - gradlePluginPortal() - maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") - maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") - - // Declare the Node.js download repository - ivy { - name = "Node.js" - setUrl("https://nodejs.org/dist/") - patternLayout { - artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") - } - metadataSources { - artifact() - } - content { - includeModule("org.nodejs", "node") - } - } - } - - pluginManagement { - - repositories { - mavenCentral() - gradlePluginPortal() - maven { - url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") - } - } - - } - -} +apply(from = "./repositories.settings.gradle.kts") diff --git a/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-js.gradle.kts b/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-js.gradle.kts index 4d1d5e9..26c4bc6 100644 --- a/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-js.gradle.kts +++ b/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-js.gradle.kts @@ -26,7 +26,7 @@ kotlin { } dependencies { - val kotlinWrappersVersion = "0.0.1-pre.263-kotlin-1.5.31" + val kotlinWrappersVersion = "0.0.1-pre.270-kotlin-1.6.0" implementation( project.dependencies.enforcedPlatform( "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}" diff --git a/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-jvm.gradle.kts index 913b1a8..3065c31 100644 --- a/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-jvm.gradle.kts +++ b/buildSrc/src/main/kotlin/dev/adamko/factoriowebmap/archetype/kotlin-jvm.gradle.kts @@ -36,6 +36,7 @@ dependencies { testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") testImplementation("io.kotest:kotest-property-jvm:$kotestVersion") testImplementation("io.kotest:kotest-assertions-json:$kotestVersion") + testImplementation("io.mockk:mockk:1.12.0") // @@ -46,8 +47,8 @@ tasks.withType().configureEach { kotlinOptions { jvmTarget = "11" - apiVersion = "1.5" - languageVersion = "1.5" + apiVersion = "1.6" + languageVersion = "1.6" } kotlinOptions.freeCompilerArgs += listOf( diff --git a/buildSrc/src/main/kotlin/dev/adamko/gradle/json-kotlin-schema-gen.gradle.kts b/buildSrc/src/main/kotlin/dev/adamko/gradle/json-kotlin-schema-gen.gradle.kts deleted file mode 100644 index 374f9f2..0000000 --- a/buildSrc/src/main/kotlin/dev/adamko/gradle/json-kotlin-schema-gen.gradle.kts +++ /dev/null @@ -1,12 +0,0 @@ -package dev.adamko.gradle - -import org.gradle.kotlin.dsl.`component-model-base` -import org.gradle.kotlin.dsl.kotlin - - -plugins { - base -} - - - diff --git a/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/TstlPlugin.kt b/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/TstlPlugin.kt deleted file mode 100644 index d506592..0000000 --- a/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/TstlPlugin.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.adamko.gradle.tstl - -import com.github.gradle.node.NodePlugin -import dev.adamko.gradle.tstl.tasks.TypescriptToLuaTask -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.BasePlugin -import org.gradle.kotlin.dsl.withType -import org.gradle.language.base.plugins.LifecycleBasePlugin - - -class TstlPlugin : Plugin { - override fun apply(project: Project) { - - project.plugins.withType { - } - - project.plugins.withType { - project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { - dependsOn(project.tasks.withType()) - } - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/tasks/TypescriptToLuaTask.kt b/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/tasks/TypescriptToLuaTask.kt deleted file mode 100644 index 4da82d3..0000000 --- a/buildSrc/src/main/kotlin/dev/adamko/gradle/tstl/tasks/TypescriptToLuaTask.kt +++ /dev/null @@ -1,50 +0,0 @@ -package dev.adamko.gradle.tstl.tasks - -import com.github.gradle.node.npm.task.* -import org.gradle.api.file.* -import org.gradle.api.provider.* -import org.gradle.api.tasks.* -import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs -import org.gradle.kotlin.dsl.* - -abstract class TypescriptToLuaTask : NpmTask() { - - @get:Internal - val intermediateOutputDir: RegularFileProperty = project.objects.fileProperty() - .convention { temporaryDir } - - @get:Internal - val intermediateOutputCanonicalPath: Provider = - intermediateOutputDir.map { it.asFile.canonicalPath } - - @get:Input - val identifier: Property = project.objects.property().convention(name) - - @get:Internal - val luaOutputDirConvention: Provider = - project.layout.buildDirectory.map { it.dir("typescriptToLua/${identifier.get()}") } - - @get:OutputDirectory - val luaOutputDir: DirectoryProperty = project.objects.directoryProperty() - .convention(luaOutputDirConvention) - - init { - group = "typescriptToLua" - - execOverrides { standardOutput = System.out } - - super.dependsOn(project.tasks.withType()) - ignoreExitValue.set(false) - } - - @TaskAction - fun convert() { - args.set(parseSpaceSeparatedArgs("-- --outDir ${intermediateOutputCanonicalPath.get()}")) - - project.delete(intermediateOutputDir.get()) - - super.exec() - - } - -} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0981cc..2751a37 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ ## compilation ## jvm = "11" -kotlin = "1.5.31" +kotlin = "1.6.0" ## libs ## http4k = "4.16.1.0" @@ -45,9 +45,9 @@ sendgrid = { group = "com.sendgrid", name = "sendgrid-java", version ## kotlin ## kotlin-bom = { group = "org.jetbrains.kotlin", name = "kotlin-bom", version.ref = "kotlin" } -kotlinx-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.3.0" } -kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.5.2" } -kotlinx-html = { group = "org.jetbrains.kotlinx", name = "kotlinx-html", version = "0.7.3" } +kotlinx-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.3.0" } +kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.6.0-RC" } +kotlinx-html = { group = "org.jetbrains.kotlinx", name = "kotlinx-html", version = "0.7.3" } ## http4k ## http4k-bom = { group = "org.http4k", name = "http4k-bom", version.ref = "http4k" } diff --git a/modules/factorio-events-data-model/build.gradle.kts b/modules/factorio-events-data-model/build.gradle.kts index 618df6e..48aae2d 100644 --- a/modules/factorio-events-data-model/build.gradle.kts +++ b/modules/factorio-events-data-model/build.gradle.kts @@ -1,4 +1,3 @@ -import org.gradle.process.internal.DefaultExecSpec import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation @@ -21,8 +20,8 @@ kotlin { compilations.configureEach { kotlinOptions { jvmTarget = "11" - apiVersion = "1.5" - languageVersion = "1.5" + apiVersion = "1.6" + languageVersion = "1.6" } } } @@ -76,7 +75,7 @@ kotlin { sourceSets.all { languageSettings.apply { - languageVersion = "1.5" + languageVersion = "1.6" // enableLanguageFeature("InlineClasses") // language feature name optIn("kotlin.OptIn") optIn("kotlin.RequiresOptIn") @@ -91,25 +90,8 @@ kotlin { } - - -//kotlin.js() -// .compilations -// .getByName(KotlinCompilation.MAIN_COMPILATION_NAME) -// .npmProject -// .useTool() - - afterEvaluate { -// val nodeJsExecTstl by tasks.creating(NodeJsExec::class) { -// group = project.name -// -// nodeArgs += listOf( -// "tstl", -// ) -// } - val kotlinJsCompilation: KotlinJsCompilation = kotlin.targets .flatMap { it.compilations } @@ -124,8 +106,7 @@ afterEvaluate { errorOutput = System.err workingDir = npmProject.dir - executable = - when (npmProject.nodeJs.requireConfigured().isWindows) { + executable = when (npmProject.nodeJs.requireConfigured().isWindows) { true -> "npx.cmd" false -> "npx" } @@ -134,58 +115,6 @@ afterEvaluate { } - tasks.create("asd") { - group = project.name - - doLast { - - val execSpec = - project.objects.newInstance(DefaultExecSpec::class.java).apply { - isIgnoreExitValue = false - standardOutput = System.out - errorOutput = System.err - } - - kotlin.targets - .flatMap { it.compilations } - .filterIsInstance() - .filter { it.name == KotlinCompilation.MAIN_COMPILATION_NAME } - .forEach { - - org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(it, "blahDeBlah") { - - } - - execSpec.workingDir = it.npmProject.dir - - execSpec.executable = - when (it.npmProject.nodeJs.requireConfigured().isWindows) { - true -> "npx.cmd" - false -> "npx" - } - - execSpec.args("tstl", "--version") - -// execSpec.commandLine - - -// it.npmProject.useTool( -// execSpec, -// "typescript-to-lua/dist/tstl.js", -// listOf(), -// listOf( "--outDir","$buildDir/testAsd"), -// listOf("--version"), -// listOf(), -// ) - } - - exec { - execSpec.copyTo(this) - } - - } - } - } diff --git a/modules/factorio-events-data-model/src/jvmMain/kotlin/dev/adamko/factorioevents/model/factorioEvents.kt b/modules/factorio-events-data-model/src/jvmMain/kotlin/dev/adamko/factorioevents/model/factorioEvents.kt index 1c6d81c..bb5d928 100644 --- a/modules/factorio-events-data-model/src/jvmMain/kotlin/dev/adamko/factorioevents/model/factorioEvents.kt +++ b/modules/factorio-events-data-model/src/jvmMain/kotlin/dev/adamko/factorioevents/model/factorioEvents.kt @@ -1,13 +1,8 @@ package dev.adamko.factorioevents.model -import dev.adamko.factorioevents.model.FBuiltInType.FNumber.F_float -import dev.adamko.factorioevents.model.FBuiltInType.FNumber.F_int -import dev.adamko.factorioevents.model.FBuiltInType.FNumber.F_uint - -import kotlinx.serialization.* -import kotlinx.serialization.builtins.* -import kotlinx.serialization.json.* -import kotlinx.serialization.modules.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonClassDiscriminator @Serializable @@ -44,7 +39,6 @@ data class EntityData( val player_index: UInt?, ) : FactorioObjectData - data class SurfaceData( override val objectName: String, val name: String, diff --git a/modules/mod/build.gradle.kts b/modules/mod/build.gradle.kts index fa0274f..e120d00 100644 --- a/modules/mod/build.gradle.kts +++ b/modules/mod/build.gradle.kts @@ -5,7 +5,6 @@ import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs plugins { idea id("dev.adamko.factoriowebmap.archetype.node") - id("dev.adamko.tstl") } val projectId: String by project.extra diff --git a/settings.gradle.kts b/settings.gradle.kts index b75fcf8..c0e4e8b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,58 +1,14 @@ rootProject.name = "factorio-web-map" - -//includeBuild("modules/protoc-gradle-plugin") - include( ":modules:mod", -// ":modules:server", ":modules:kt-rcon", ":modules:factorio-events-data-model", -// ":modules:factorio-events-data-model2", ":modules:factorio-events-processor", ":modules:factorio-events-kafka-pipe", ) - enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -@Suppress("UnstableApiUsage") -dependencyResolutionManagement { - - // https://github.com/gradle/gradle/issues/15754#issuecomment-763614651 - // https://github.com/gradle/gradle/blob/09fcaacc9848f09aa584b4119be9271bee6916e6/build-logic/build-logic-base/settings-plugin/src/main/kotlin/gradlebuild.repositories.settings.gradle.kts#L68 - - // Cannot use 'FAIL_ON_PROJECT_REPOS' because - // - the 'gradle-guides-plugin' adds a repo (which it should not do) - // - the 'kotlin-gradle-plugin' adds a repo (and removes it afterwards) to download NodeJS - repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) - - repositories { - mavenCentral() - maven("https://jitpack.io") - maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") - maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") - - // Declare the Node.js download repository - ivy("https://nodejs.org/dist/") { - name = "Node Distributions at $url" - patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") } - metadataSources { artifact() } - content { includeModule("org.nodejs", "node") } - } - } - - pluginManagement { - - repositories { - mavenCentral() - gradlePluginPortal() - maven { - url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") - } - } - - } - -} +apply(from = "./buildSrc/repositories.settings.gradle.kts")