tidy up Gradle config, standardise a group for Factorio Mod tasks

This commit is contained in:
Adam 2022-06-26 14:56:53 +02:00
parent f2ae951b1d
commit dacb6f62c4
13 changed files with 83 additions and 174 deletions

View file

@ -1,4 +1,4 @@
package dev.adamko.kafkatorio.factoriomod
package dev.adamko.kafkatorio.factoriomod.portal
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
@ -98,7 +98,7 @@ class FactorioModPortalPublishClient(
require(response.status.isSuccess()) { "init upload request failed" }
return when (initUploadResponse) {
is Failure -> error(initUploadResponse)
is Failure -> error(initUploadResponse)
is InitUploadResponse.Success -> initUploadResponse
}
}

View file

@ -1,5 +1,6 @@
package dev.adamko.kafkatorio.factoriomod
package dev.adamko.kafkatorio.factoriomod.portal
import dev.adamko.kafkatorio.factoriomod.FactorioMod
import io.ktor.http.URLBuilder
import io.ktor.http.takeFrom
import javax.inject.Inject
@ -59,7 +60,7 @@ abstract class FactorioModPublishTask @Inject constructor(
init {
group = "factorio"
group = FactorioMod.TASK_GROUP
}

View file

@ -1,4 +1,4 @@
package dev.adamko.kafkatorio.factoriomod
package dev.adamko.kafkatorio.factoriomod.portal
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View file

@ -0,0 +1,12 @@
package dev.adamko.kafkatorio.factoriomod
object FactorioMod {
const val TASK_GROUP = "factorioMod"
/** Lifecycle task for publishing the mod locally */
const val PUBLISH_MOD_LOCAL_TASK_NAME = "publishModLocal"
const val PUBLISH_MOD_TASK_NAME = "publishMod"
}

View file

@ -12,16 +12,8 @@ val projectJvmTarget = "11"
dependencies {
// implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// testImplementation(platform("org.junit:junit-bom:${Versions.junit}"))
testImplementation("org.junit.jupiter:junit-jupiter")
// testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
// because("Only needed to run tests in a version of IntelliJ IDEA that bundles older versions")
// }
// testImplementation(platform("io.kotest:kotest-bom:${Versions.kotest}"))
testImplementation("io.kotest:kotest-runner-junit5")
testImplementation("io.kotest:kotest-assertions-core")
testImplementation("io.kotest:kotest-property")

View file

@ -8,7 +8,7 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
abstract class GenerateTypescriptTask @Inject constructor(
abstract class GenerateTypeScriptTask @Inject constructor(
private val fileOps: FileSystemOperations,
) : JavaExec() {

View file

@ -1,4 +1,4 @@
import dev.adamko.kafkatorio.factoriomod.FactorioModPublishTask
import dev.adamko.kafkatorio.factoriomod.portal.FactorioModPublishTask
import dev.adamko.kafkatorio.gradle.asConsumer
import dev.adamko.kafkatorio.gradle.asProvider
import dev.adamko.kafkatorio.gradle.dropDirectory
@ -43,7 +43,7 @@ val projectTokensX = projectTokens.apply {
put("mod.name", modName)
put("mod.title", "Kafkatorio Events")
put("mod.description", modDescription)
put("factorio.version", modFactorioCompatibility.get())
put("factorio.version", modFactorioCompatibility)
}
val tsSrcDir: Directory = layout.projectDirectory.dir("src/main/typescript")
@ -139,7 +139,8 @@ distributions {
from(licenseFile)
from(typescriptToLua.map { it.outputDirectory })
filesNotMatching("**/*.png") {
filter<ReplaceTokens>("tokens" to projectTokens.get())
val tokens: MutableMap<String, String> = projectTokens.get()
filter<ReplaceTokens>("tokens" to tokens)
}
includeEmptyDirs = false
exclude {

View file

@ -1,6 +1,6 @@
import dev.adamko.kafkatorio.gradle.asProvider
import dev.adamko.kafkatorio.gradle.typescriptAttributes
import dev.adamko.kafkatorio.task.GenerateTypescriptTask
import dev.adamko.kafkatorio.task.GenerateTypeScriptTask
plugins {
@ -14,25 +14,8 @@ plugins {
kotlin {
js(IR) {
// binaries.executable()
browser {}
// browser{} causes this error:
// Cannot load "webpack", it is not registered!
// Perhaps you are missing some plugin?
// Cannot load "sourcemap", it is not registered!
// Perhaps you are missing some plugin?
// Server start failed on port 9876: Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
// browser {
// runTask {
// sourceMaps = true
// }
// testTask {
// useKarma {
// useChromeHeadless()
// }
// }
// }
// nodejs()
// this is a library - don't set binaries.executable()
}
jvm {
val main by compilations.getting {
@ -75,9 +58,6 @@ kotlin {
implementation(project.dependencies.platform(libs.kotest.bom))
implementation("io.kotest:kotest-framework-engine")
// implementation("io.kotest:kotest-assertions-core")
// implementation("io.kotest:kotest-property")
// implementation("io.kotest:kotest-assertions-json")
implementation(libs.kotest.core)
implementation(libs.kotest.datatest)
implementation(libs.kotest.prop)
@ -88,10 +68,7 @@ kotlin {
val jvmMain by getting {
dependencies {
implementation("com.github.aSemy:ts-generator:v1.2.1")
// implementation("com.github.ntrrgc:ts-generator:1.1.2")
implementation(kotlin("reflect"))
// implementation("com.github.adamko-dev:kotlinx-serialization-typescript-generator:0.0.5")
}
}
@ -114,7 +91,7 @@ val mainCompilation: Provider<FileCollection> =
kotlin.jvm().compilations.named("main").map { it.runtimeDependencyFiles }
val generateTypescript by tasks.registering(GenerateTypescriptTask::class) {
val generateTypeScript by tasks.registering(GenerateTypeScriptTask::class) {
dependsOn(jvmJar)
classpath(
jvmJar,
@ -125,68 +102,26 @@ val generateTypescript by tasks.registering(GenerateTypescriptTask::class) {
args(temporaryDir.canonicalPath)
}
//val generateTypescript2 by tasks.registering(JavaExec::class) {
// group = "kt2ts"
//
// dependsOn(jvmJar)
//
// inputs.files(mainCompilation)
//
// classpath(
// jvmJar,
// mainCompilation,
// )
// mainClass.set("dev.adamko.kafkatorio.events.schema.Kt2ts2Kt")
//
// args(temporaryDir)
//
// val buildOutput = layout.buildDirectory.dir("generated/typescript")
// outputs.dir(buildOutput)
//
// doFirst {
// delete(temporaryDir)
// mkdir(temporaryDir)
// }
//
// doLast {
// sync {
// from(temporaryDir)
// into(buildOutput)
// include("**/*.ts")
// }
// }
//}
val schemaTsDistributionName: Provider<String> = providers.provider {
"${rootProject.name}-${project.name}"
}
val generateTypescriptOutputFiles: Provider<FileTree> =
generateTypescript.map { it.outputs.files.asFileTree }
val generateTypeScriptOutputFiles: Provider<FileTree> =
generateTypeScript.map { it.outputs.files.asFileTree }
val schemaTs by distributions.registering {
distributionBaseName.set(schemaTsDistributionName)
contents {
from(generateTypescriptOutputFiles)
from(generateTypeScriptOutputFiles)
}
}
val schemaTsZipTask: TaskProvider<Zip> = tasks.named<Zip>("${schemaTs.name}DistZip")
val schemaTsZipTaskArchiveFile: Provider<RegularFile> = schemaTsZipTask.flatMap { it.archiveFile }
val typescriptModelGenerated: Configuration by configurations.creating {
val typeScriptModelGenerated: Configuration by configurations.creating {
asProvider()
typescriptAttributes(objects)
outgoing.artifact(schemaTsZipTaskArchiveFile)
}
//tasks.matching {
// it.name == "jsGenerateExternalsIntegrated"
//}.configureEach {
// @Suppress("UnstableApiUsage")
// notCompatibleWithConfigurationCache("try to prevent 'Projects must be configuring' error")
//// outputs.upToDateWhen { true }
// dependsOn(":kotlinNpmInstall")
//}

View file

@ -1,12 +1,14 @@
import dev.adamko.kafkatorio.task.KafkaConsumerGroupsTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
dev.adamko.kafkatorio.lang.`kotlin-jvm`
kotlin("plugin.serialization")
application
}
description = """
Receive raw Factorio Events from Kafka and process them into targeted topics or data formats.
@ -17,6 +19,7 @@ val projectId: String by project.extra
val kafkaStateDir: Directory = layout.projectDirectory.dir("kafka-state")
dependencies {
implementation(platform(projects.modules.versionsPlatform))
@ -49,9 +52,6 @@ dependencies {
implementation(libs.bundles.hoplite)
}
//configurations.all {
// resolutionStrategy.cacheDynamicVersionsFor(1, TimeUnit.MINUTES)
//}
application {
mainClass.set("dev.adamko.kafkatorio.processor.EventProcessorKt")
@ -93,7 +93,3 @@ idea {
excludeDirs = excludeDirs + kafkaStateDir.asFile
}
}
//tasks.withType<KotlinNpmInstallTask>().all {
// notCompatibleWithConfigurationCache("error: Projects must be configuring")
//}

View file

@ -1,3 +1,4 @@
import dev.adamko.kafkatorio.factoriomod.FactorioMod
import dev.adamko.kafkatorio.gradle.asConsumer
import dev.adamko.kafkatorio.gradle.factorioModAttributes
import dev.adamko.kafkatorio.gradle.not
@ -34,10 +35,11 @@ dependencies {
factorioMod(projects.modules.eventsMod)
}
//<editor-fold desc="Mod deployment tasks">
val deployModToClient by tasks.registering(Copy::class) {
description = "Copy the mod to the Factorio client"
group = project.name
group = FactorioMod.TASK_GROUP
onlyIf { clientModsDirectory.orNull?.asFile?.exists() == true }
@ -50,13 +52,14 @@ val deployModToClient by tasks.registering(Copy::class) {
}
//</editor-fold>
//<editor-fold desc="Factorio client lifecycle tasks">
fun ExecOperations.isFactorioRunning(): Spec<Task> = ProcessRunningSpec(this, "factorio.exe")
val clientLaunch by tasks.registering(Exec::class) {
description = "Run Factorio Steam game client"
group = project.name
description = "Run local Factorio Steam game client"
group = FactorioMod.TASK_GROUP
onlyIf(!serviceOf<ExecOperations>().isFactorioRunning())
onlyIf { steamExe.orNull?.asFile?.exists() == true }
@ -74,8 +77,8 @@ val clientLaunch by tasks.registering(Exec::class) {
}
val clientKill by tasks.registering(Exec::class) {
description = "Run Factorio Steam game client"
group = project.name
description = "Stop the local Factorio Steam game client"
group = FactorioMod.TASK_GROUP
onlyIf(serviceOf<ExecOperations>().isFactorioRunning())
@ -84,7 +87,12 @@ val clientKill by tasks.registering(Exec::class) {
}
//</editor-fold>
tasks.build { dependsOn(deployModToClient) }
tasks.register(FactorioMod.PUBLISH_MOD_LOCAL_TASK_NAME) {
group = FactorioMod.TASK_GROUP
dependsOn(deployModToClient)
}
tasks.processRun {
dependsOn(

View file

@ -1,3 +1,4 @@
import dev.adamko.kafkatorio.factoriomod.FactorioMod
import dev.adamko.kafkatorio.gradle.asConsumer
import dev.adamko.kafkatorio.gradle.factorioModAttributes
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
@ -6,21 +7,25 @@ plugins {
dev.adamko.kafkatorio.infra.`docker-compose`
}
val dockerSrcDir: Directory by extra
val factorioServerDataDir: Directory = dockerSrcDir.dir("factorio-server")
val factorioMod: Configuration by configurations.creating {
asConsumer()
factorioModAttributes(objects)
}
dependencies {
factorioMod(projects.modules.eventsMod)
}
val deployModToServer by tasks.registering(Copy::class) {
description = "Copy the mod to the Factorio Docker server"
group = project.name
group = FactorioMod.TASK_GROUP
dependsOn(factorioMod)
@ -34,10 +39,12 @@ val deployModToServer by tasks.registering(Copy::class) {
}
}
tasks.dockerDown {
commandLine = parseSpaceSeparatedArgs(""" docker-compose stop """)
}
tasks.dockerUp {
dependsOn(
deployModToServer,
@ -45,11 +52,16 @@ tasks.dockerUp {
)
}
tasks.dockerEnv {
properties("FACTORIO_VERSION" to libs.versions.factorio.get())
}
tasks.build { dependsOn(deployModToServer) }
tasks.register(FactorioMod.PUBLISH_MOD_LOCAL_TASK_NAME) {
group = FactorioMod.TASK_GROUP
dependsOn(deployModToServer)
}
idea {

View file

@ -1,4 +1,3 @@
import dev.adamko.kafkatorio.gradle.taskProvider
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
@ -17,6 +16,7 @@ kvision {
enableHiddenKotlinJsStore.set(false)
}
rootProject.extensions.configure<NodeJsRootExtension> {
// https://github.com/rjaros/kvision/issues/410
versions.webpackCli.version = "4.10.0"
@ -48,13 +48,9 @@ afterEvaluate {
kotlin {
js(IR) {
// browser()
// binaries.executable()
// }
//
// js("frontend", IR) {
// nodejs()
browser {
binaries.executable()
runTask {
outputFileName = "main.bundle.js"
sourceMaps = false
@ -87,16 +83,11 @@ kotlin {
}
}
}
binaries.executable()
// compilations["main"].packageJson {
// this.devDependencies["webpack-dev-server"] = "4.9.1"
// }
}
// jvm("backend") {
//
// }
sourceSets {
all {
@ -106,7 +97,6 @@ kotlin {
}
}
// val commonMain by getting {
main {
dependencies {
implementation(dependencies.platform(libs.kotlinx.coroutines.bom))
@ -117,13 +107,6 @@ kotlin {
implementation(projects.modules.eventsSchema)
implementation(libs.kotlinx.html)
// }
// }
// val jsMain by getting {
// dependsOn(commonMain)
//
// dependencies {
implementation(projects.modules.eventsSchema)
@ -154,37 +137,15 @@ kotlin {
// implementation(dependencies.platform(devNpm("webpack-dev-server", "4.9.1")))
}
// val webDir = file("src/main/web")
resources.srcDir("src/main/web")
// resources.srcDir("src/main/resources")
// kotlin.srcDir("src/main/kotlin")
}
// val frontendMain by getting {
// dependsOn(jsMain)
//// resources.srcDir("src/main/web")
//// resources.srcDir("src/main/resources")
// }
//
// val jsTest by getting {
// dependencies {
// implementation(kotlin("test-js"))
//
// kvision("kvision-testutils")
//
//// implementation(npm("karma", "^6.3.16"))
// }
//
// kotlin.srcDir("src/test/kotlin")
// }
test {
dependencies {
implementation(kotlin("test-js"))
kvision("kvision-testutils")
// implementation(npm("karma", "^6.3.16"))
}
}
@ -221,22 +182,22 @@ fun KotlinDependencyHandler.kvision(
//evaluationDependsOn(projects.modules.eventsSchema.dependencyProject.path)
// stop warnings when building
tasks.configureEach {
when (name) {
"productionExecutableCompileSync" ->
dependsOn(taskProvider("compileProductionExecutableKotlinJs"))
"testTestDevelopmentExecutableCompileSync" ->
dependsOn(taskProvider("compileTestDevelopmentExecutableKotlinJs"))
// "jsTestTestDevelopmentExecutableCompileSync" ->
// dependsOn(taskProvider("compileTestDevelopmentExecutableKotlinFrontend"))
// "jsProductionExecutableCompileSync" ->
// dependsOn(taskProvider("compileProductionExecutableKotlinFrontend"))
"browserDevelopmentRun" ->
dependsOn(taskProvider("browserDevelopmentWebpack"))
"browserDevelopmentWebpack" ->
dependsOn(taskProvider("assemble"))
"browserProductionWebpack" ->
dependsOn(taskProvider("developmentExecutableCompileSync"))
}
}
//// stop warnings when building
//tasks.configureEach {
// when (name) {
// "productionExecutableCompileSync" ->
// dependsOn(taskProvider("compileProductionExecutableKotlinJs"))
// "testTestDevelopmentExecutableCompileSync" ->
// dependsOn(taskProvider("compileTestDevelopmentExecutableKotlinJs"))
//// "jsTestTestDevelopmentExecutableCompileSync" ->
//// dependsOn(taskProvider("compileTestDevelopmentExecutableKotlinFrontend"))
//// "jsProductionExecutableCompileSync" ->
//// dependsOn(taskProvider("compileProductionExecutableKotlinFrontend"))
// "browserDevelopmentRun" ->
// dependsOn(taskProvider("browserDevelopmentWebpack"))
// "browserDevelopmentWebpack" ->
// dependsOn(taskProvider("assemble"))
// "browserProductionWebpack" ->
// dependsOn(taskProvider("developmentExecutableCompileSync"))
// }
//}

View file

@ -25,14 +25,5 @@ apply(from = "./buildSrc/repositories.settings.gradle.kts")
@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
// repositories {
// maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
//// content {
//// includeGroup("dev.adamko.kxstsgen")
//// }
// }
// }
}