@@ -145,12 +145,49 @@ val generateBuildConfig = tasks.register("generateBuildConfig") {
145
145
}
146
146
}
147
147
148
+ // Generate TestCredentials from test_credentials.json
149
+ val generateTestCredentials = tasks.register(" generateTestCredentials" ) {
150
+ val outputDir = layout.buildDirectory.dir(" generated/source/testCredentials" )
151
+ val cargoProjectRoot = rootProject.ext.get(" cargoProjectRoot" ) as String
152
+ val credentialsFile = file(" $cargoProjectRoot /test_credentials.json" )
153
+
154
+ inputs.file(credentialsFile)
155
+ outputs.dir(outputDir)
156
+
157
+ doLast {
158
+ val json = groovy.json.JsonSlurper ().parseText(credentialsFile.readText()) as Map <* , * >
159
+
160
+ val testCredentialsFile = outputDir.get().file(" rs/wordpress/example/TestCredentials.kt" ).asFile
161
+ testCredentialsFile.parentFile.mkdirs()
162
+ testCredentialsFile.writeText("""
163
+ package rs.wordpress.example
164
+
165
+ object TestCredentials {
166
+ const val SITE_URL = "${json[" site_url" ]} "
167
+ const val ADMIN_USERNAME = "${json[" admin_username" ]} "
168
+ const val ADMIN_PASSWORD = "${json[" admin_password" ]} "
169
+ const val SUBSCRIBER_USERNAME = "${json[" subscriber_username" ]} "
170
+ const val SUBSCRIBER_PASSWORD = "${json[" subscriber_password" ]} "
171
+ }
172
+ """ .trimIndent())
173
+ }
174
+ }
175
+
148
176
kotlin.sourceSets.getByName(" desktopMain" ) {
149
177
kotlin.srcDir(layout.buildDirectory.dir(" generated/source/buildConfig" ))
150
178
}
151
179
180
+ kotlin.sourceSets.getByName(" commonMain" ) {
181
+ kotlin.srcDir(layout.buildDirectory.dir(" generated/source/testCredentials" ))
182
+ }
183
+
152
184
tasks.named(" compileKotlinDesktop" ).configure {
153
185
dependsOn(generateBuildConfig)
186
+ dependsOn(generateTestCredentials)
187
+ }
188
+
189
+ tasks.matching { it.name.startsWith(" compileKotlin" ) && it.name.contains(" Android" ) }.configureEach {
190
+ dependsOn(generateTestCredentials)
154
191
}
155
192
156
193
tasks.named(" desktopProcessResources" ).configure {
0 commit comments