@@ -2,8 +2,6 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
22import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
33import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44import org.springframework.boot.gradle.tasks.bundling.BootJar
5- import java.io.FileInputStream
6- import java.util.Properties
75
86val policy: String by System .getProperties()
97
6361 }
6462}
6563
66-
67- val kotlinComposeWasmStdlibWasmFile: Configuration by configurations.creating {
64+ val kotlinComposeWasmStdlibFile: Configuration by configurations.creating {
6865 isTransitive = false
6966 isCanBeResolved = true
7067 isCanBeConsumed = false
@@ -106,41 +103,46 @@ dependencies {
106103 }
107104 testImplementation(libs.kotlinx.coroutines.test)
108105
109- kotlinComposeWasmStdlibWasmFile (project(" :cache-maker" ))
106+ kotlinComposeWasmStdlibFile (project(" :cache-maker" ))
110107}
111108
112- fun buildPropertyFile () {
113- rootDir.resolve(" src/main/resources/${propertyFile} " ).apply {
114- println (" Generate properties into $absolutePath " )
115- parentFile.mkdirs()
116- writeText(generateProperties())
109+ fun Project.generateProperties (
110+ prefix : String = "",
111+ ): Map <String , String > = mapOf (
112+ " kotlin.version" to kotlinVersion,
113+ " policy.file" to prefix + policy,
114+ " indexes.file" to prefix + indexes,
115+ " indexesJs.file" to prefix + indexesJs,
116+ " indexesWasm.file" to prefix + indexesWasm,
117+ " indexesComposeWasm.file" to prefix + indexesComposeWasm,
118+ " libraries.folder.jvm" to prefix + libJVM,
119+ " libraries.folder.js" to prefix + libJS,
120+ " libraries.folder.wasm" to prefix + libWasm,
121+ " libraries.folder.compose-wasm" to prefix + libComposeWasm,
122+ " libraries.folder.compose-wasm-compiler-plugins" to prefix + libComposeWasmCompilerPlugins,
123+ " libraries.folder.compiler-plugins" to prefix + compilerPluginsForJVM,
124+ " spring.mvc.pathmatch.matching-strategy" to " ant_path_matcher" ,
125+ " server.compression.enabled" to " true" ,
126+ " server.compression.mime-types" to " application/json,text/javascript,application/wasm" ,
127+ " skiko.version" to libs.versions.skiko.get(),
128+ )
129+
130+ val propertiesGenerator by tasks.registering(PropertiesGenerator ::class ) {
131+ dependsOn(kotlinComposeWasmStdlibFile)
132+ propertiesFile.fileValue(rootDir.resolve(" src/main/resources/${propertyFile} " ))
133+ hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
134+ generateProperties().forEach { (name, value) ->
135+ propertiesMap.put(name, value)
117136 }
118137}
119138
120- fun generateProperties (prefix : String = "") = """
121- # this file is autogenerated by build.gradle.kts
122- kotlin.version=${kotlinVersion}
123- policy.file=${prefix + policy}
124- indexes.file=${prefix + indexes}
125- indexesJs.file=${prefix + indexesJs}
126- indexesWasm.file=${prefix + indexesWasm}
127- indexesComposeWasm.file=${prefix + indexesComposeWasm}
128- libraries.folder.jvm=${prefix + libJVM}
129- libraries.folder.js=${prefix + libJS}
130- libraries.folder.wasm=${prefix + libWasm}
131- libraries.folder.compose-wasm=${prefix + libComposeWasm}
132- libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPlugins}
133- libraries.folder.compiler-plugins=${prefix + compilerPluginsForJVM}
134- spring.mvc.pathmatch.matching-strategy=ant_path_matcher
135- server.compression.enabled=true
136- server.compression.mime-types=application/json,text/javascript,application/wasm
137- skiko.version=${libs.versions.skiko.get()}
138- """ .trimIndent()
139-
140- val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater ::class ) {
141- dependsOn(kotlinComposeWasmStdlibWasmFile)
142- propertiesPath.set(rootDir.resolve(" src/main/resources/${propertyFile} " ).absolutePath)
143- hashableFile.set(kotlinComposeWasmStdlibWasmFile.singleFile)
139+ val lambdaPropertiesGenerator by tasks.registering(PropertiesGenerator ::class ) {
140+ dependsOn(kotlinComposeWasmStdlibFile)
141+ propertiesFile.set(layout.buildDirectory.file(" tmp/propertiesGenerator/${propertyFile} " ))
142+ hashableFile.set(kotlinComposeWasmStdlibFile.singleFile)
143+ generateProperties(lambdaPrefix).forEach { (name, value) ->
144+ propertiesMap.put(name, value)
145+ }
144146}
145147
146148tasks.withType<KotlinCompile > {
@@ -149,8 +151,7 @@ tasks.withType<KotlinCompile> {
149151 }
150152 dependsOn(" :executors:jar" )
151153 dependsOn(" :indexation:run" )
152- dependsOn(composeWasmPropertiesUpdater)
153- buildPropertyFile()
154+ dependsOn(propertiesGenerator)
154155}
155156println (" Using Kotlin compiler ${libs.versions.kotlin.get()} " )
156157
@@ -161,19 +162,12 @@ tasks.withType<BootJar> {
161162
162163val buildLambda by tasks.creating(Zip ::class ) {
163164 val propertyFile = propertyFile
164- val propertyFileContent = generateProperties(lambdaPrefix)
165165
166166 from(tasks.compileKotlin)
167167 from(tasks.processResources) {
168- eachFile {
169- if (name == propertyFile) {
170- val properties = Properties ().apply { load(FileInputStream (file)) }
171- val composeWasmHash = properties.get(" dependencies.compose.wasm" )
172- file.writeText(propertyFileContent)
173- file.appendText(" \n dependencies.compose.wasm=$composeWasmHash " )
174- }
175- }
168+ exclude(propertyFile)
176169 }
170+ from(lambdaPropertiesGenerator)
177171 from(policy)
178172 from(indexes)
179173 from(indexesJs)
@@ -183,16 +177,16 @@ val buildLambda by tasks.creating(Zip::class) {
183177 from(libWasmFolder) { into(libWasm) }
184178 from(libComposeWasmFolder) { into(libComposeWasm) }
185179 from(libJVMFolder) { into(libJVM) }
186- from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
180+ from(compilerPluginsForJVMFolder) { into(compilerPluginsForJVM) }
187181 from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
188- dependsOn(kotlinComposeWasmStdlibWasmFile )
182+ dependsOn(kotlinComposeWasmStdlibFile )
189183 into(" lib" ) {
190184 from(configurations.compileClasspath) { exclude(" tomcat-embed-*" ) }
191185 }
192186}
193187
194188tasks.named<Copy >(" processResources" ) {
195- dependsOn(composeWasmPropertiesUpdater )
189+ dependsOn(propertiesGenerator )
196190}
197191
198192tasks.withType<Test > {
0 commit comments