@@ -4,8 +4,6 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
44import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
55import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
66import org.springframework.boot.gradle.tasks.bundling.BootJar
7- import java.io.FileInputStream
8- import java.util.Properties
97
108val policy: String by System .getProperties()
119
@@ -36,8 +34,7 @@ allprojects {
3634 }
3735}
3836
39-
40- val kotlinComposeWasmStdlibWasmFile: Configuration by configurations.creating {
37+ val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
4138 isTransitive = false
4239 isCanBeResolved = true
4340 isCanBeConsumed = false
@@ -79,42 +76,47 @@ dependencies {
7976 }
8077 testImplementation(libs.kotlinx.coroutines.test)
8178
82- kotlinComposeWasmStdlibWasmFile (project(" :cache-maker" ))
79+ kotlinComposeWasmStdlibFile (project(" :cache-maker" ))
8380}
8481
85- fun buildPropertyFile () {
86- rootDir.resolve(" src/main/resources/${propertyFile} " ).apply {
87- println (" Generate properties into $absolutePath " )
88- parentFile.mkdirs()
89- writeText(generateProperties())
82+ fun Project.generateProperties (
83+ prefix : String = "",
84+ ): Map <String , String > = mapOf (
85+ " kotlin.version" to kotlinVersion,
86+ " policy.file" to prefix + policy,
87+ " indexes.file" to prefix + indexes,
88+ " indexesJs.file" to prefix + indexesJs,
89+ " indexesWasm.file" to prefix + indexesWasm,
90+ " indexesComposeWasm.file" to prefix + indexesComposeWasm,
91+ " libraries.folder.jvm" to prefix + libJVM,
92+ " libraries.folder.js" to prefix + libJS,
93+ " libraries.folder.wasm" to prefix + libWasm,
94+ " libraries.folder.compose-wasm" to prefix + libComposeWasm,
95+ " libraries.folder.compose-wasm-compiler-plugins" to prefix + libComposeWasmCompilerPlugins,
96+ " libraries.folder.compiler-plugins" to prefix + compilerPluginsForJVM,
97+ " spring.mvc.pathmatch.matching-strategy" to " ant_path_matcher" ,
98+ " server.compression.enabled" to " true" ,
99+ " server.compression.mime-types" to " application/json,text/javascript,application/wasm" ,
100+ " springdoc.swagger-ui.path:" to " /api-docs/swagger-ui.html" ,
101+ " skiko.version" to libs.versions.skiko.get(),
102+ )
103+
104+ val propertiesGenerator by tasks.registering(PropertiesGenerator ::class ) {
105+ dependsOn(kotlinComposeWasmStdlibFile)
106+ propertiesFile.fileValue(rootDir.resolve(" src/main/resources/${propertyFile} " ))
107+ hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
108+ generateProperties().forEach { (name, value) ->
109+ propertiesMap.put(name, value)
90110 }
91111}
92112
93- fun generateProperties (prefix : String = "") = """
94- # this file is autogenerated by build.gradle.kts
95- kotlin.version=${kotlinVersion}
96- policy.file=${prefix + policy}
97- indexes.file=${prefix + indexes}
98- indexesJs.file=${prefix + indexesJs}
99- indexesWasm.file=${prefix + indexesWasm}
100- indexesComposeWasm.file=${prefix + indexesComposeWasm}
101- libraries.folder.jvm=${prefix + libJVM}
102- libraries.folder.js=${prefix + libJS}
103- libraries.folder.wasm=${prefix + libWasm}
104- libraries.folder.compose-wasm=${prefix + libComposeWasm}
105- libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPlugins}
106- libraries.folder.compiler-plugins=${prefix + compilerPluginsForJVM}
107- spring.mvc.pathmatch.matching-strategy=ant_path_matcher
108- server.compression.enabled=true
109- server.compression.mime-types=application/json,text/javascript,application/wasm
110- springdoc.swagger-ui.path: /api-docs/swagger-ui.html
111- skiko.version=${libs.versions.skiko.get()}
112- """ .trimIndent()
113-
114- val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater ::class ) {
115- dependsOn(kotlinComposeWasmStdlibWasmFile)
116- propertiesPath.set(rootDir.resolve(" src/main/resources/${propertyFile} " ).absolutePath)
117- hashableFile.set(kotlinComposeWasmStdlibWasmFile.singleFile)
113+ val lambdaPropertiesGenerator by tasks.registering(PropertiesGenerator ::class ) {
114+ dependsOn(kotlinComposeWasmStdlibFile)
115+ propertiesFile.set(layout.buildDirectory.file(" tmp/propertiesGenerator/${propertyFile} " ))
116+ hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
117+ generateProperties(lambdaPrefix).forEach { (name, value) ->
118+ propertiesMap.put(name, value)
119+ }
118120}
119121
120122tasks.withType<KotlinCompile > {
@@ -123,8 +125,7 @@ tasks.withType<KotlinCompile> {
123125 }
124126 dependsOn(" :executors:jar" )
125127 dependsOn(" :indexation:run" )
126- dependsOn(composeWasmPropertiesUpdater)
127- buildPropertyFile()
128+ dependsOn(propertiesGenerator)
128129}
129130println (" Using Kotlin compiler ${libs.versions.kotlin.get()} " )
130131
@@ -135,19 +136,12 @@ tasks.withType<BootJar> {
135136
136137val buildLambda by tasks.creating(Zip ::class ) {
137138 val propertyFile = propertyFile
138- val propertyFileContent = generateProperties(lambdaPrefix)
139139
140140 from(tasks.compileKotlin)
141141 from(tasks.processResources) {
142- eachFile {
143- if (name == propertyFile) {
144- val properties = Properties ().apply { load(FileInputStream (file)) }
145- val composeWasmHash = properties.get(" dependencies.compose.wasm" )
146- file.writeText(propertyFileContent)
147- file.appendText(" \n dependencies.compose.wasm=$composeWasmHash " )
148- }
149- }
142+ exclude(propertyFile)
150143 }
144+ from(lambdaPropertiesGenerator)
151145 from(policy)
152146 from(indexes)
153147 from(indexesJs)
@@ -157,16 +151,16 @@ val buildLambda by tasks.creating(Zip::class) {
157151 from(libWasmFolder) { into(libWasm) }
158152 from(libComposeWasmFolder) { into(libComposeWasm) }
159153 from(libJVMFolder) { into(libJVM) }
160- from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
154+ from(compilerPluginsForJVMFolder) { into(compilerPluginsForJVM) }
161155 from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
162- dependsOn(kotlinComposeWasmStdlibWasmFile )
156+ dependsOn(kotlinComposeWasmStdlibFile )
163157 into(" lib" ) {
164158 from(configurations.compileClasspath) { exclude(" tomcat-embed-*" ) }
165159 }
166160}
167161
168162tasks.named<Copy >(" processResources" ) {
169- dependsOn(composeWasmPropertiesUpdater )
163+ dependsOn(propertiesGenerator )
170164}
171165
172166tasks.withType<Test > {
0 commit comments