Justin
09/27/2019, 7:42 PMbasher
09/27/2019, 7:44 PMJustin
09/27/2019, 7:44 PMproject/src/commonTest/resources/
val filePath: String = System.getProperty("user.dir") + "/src/commonTest/resources/" + fileName
basher
09/27/2019, 7:46 PMobject
or something). You'd spit out that file in your build
dir somewhere and then add that folder to your commonTest sourceSetJustin
09/27/2019, 7:46 PMbasher
09/27/2019, 7:48 PMBuildConfig
. one sec. sample code comingJustin
09/27/2019, 7:48 PMbasher
09/27/2019, 7:52 PMafterEvaluate {
tasks.register("generateTheCodes") {
def packageRoot = file("build/mycodgen/kotlin/com/<package-path>")
def buildConfigFile = new File(packageRoot, "BuildConfig.kt")
outputs.file(buildConfigFile)
doLast {
// make the directory tree
mkdir packageRoot
buildConfigFile.text = ""
buildConfigFile << """package <your-package>
|object MyBuildConfig {
| const val resourcesPath = ${file("src/commonTest/resources").path}
|}
""".stripMargin().stripIndent()
}
}
// Include this in our source sets
kotlin.sourceSets.named("commonTest") {
kotlin.srcDirs += uidsRoot
}
// Ensure this runs before any compile task
tasks.withType(AbstractCompile.class).each {
it.configure {
dependsOn 'generateTheCodes'
}
}
}
generateTheCodes
which outputs a .kt file that has an object
in it, then at the end we add it to commonTest sources and add it to the task graph (with a bit of a broad brush, but should work fine)Justin
09/27/2019, 7:53 PMbasher
09/27/2019, 7:53 PMJustin
09/27/2019, 7:53 PMbasher
09/27/2019, 7:53 PMJustin
09/27/2019, 7:54 PMbasher
09/27/2019, 7:54 PMJustin
09/27/2019, 7:56 PMbasher
09/27/2019, 7:56 PMJustin
09/27/2019, 7:56 PMbasher
09/27/2019, 7:58 PMbuild/mybuildconfig
Justin
09/27/2019, 7:58 PMbasher
09/27/2019, 7:58 PMbuild/mybuildconfig/com/mycompany/mypackage/
Justin
09/27/2019, 7:59 PMuidsRoot
supposed to point to?basher
09/27/2019, 8:35 PMJustin
09/27/2019, 9:01 PMbuild/<package>
, but I still can't reference BuildConfig.resourcesPath
from the files in commonTest
(suggesting that something's not working with adding the dir to the sourceset)?basher
09/27/2019, 9:01 PMJustin
09/27/2019, 9:02 PMafterEvaluate {
val generateBuildConfig = tasks.register("generateBuildConfig") {
val packageRoot = file("build/codegen/kotlin/com/n8p6/enkounter/")
val buildConfigFile = File(packageRoot,"BuildConfig.kt")
outputs.file(buildConfigFile)
doLast {
mkdir(packageRoot)
buildConfigFile.writeText("""
package com.n8p6.enkounter
object BuildConfig {
const val resourcesPath: String = "${file("src/commonTest/kotlin/com/n8p6/enkounter/resources").path}"
}
""".trimMargin().trimIndent()
)
}
}
kotlin.sourceSets.named("commonTest") {
kotlin.srcDirs += file("build/codegen/kotlin/com/n8p6/enkounter")
}
tasks.withType<AbstractCompile>().forEach {
it.dependsOn(generateBuildConfig)
}
}
basher
09/27/2019, 9:04 PMJustin
09/27/2019, 9:04 PMbasher
09/27/2019, 9:04 PMkotlin.srcDirs += file("build/codegen/kotlin/com/n8p6/enkounter")
should be kotlin.srcDirs += file("build/codegen")
Justin
09/27/2019, 9:04 PMbasher
09/27/2019, 9:05 PMJustin
09/27/2019, 9:24 PMcommonTest.kotlin.setSrcDirs(commonTest.kotlin.srcDirs + "build/codegen")
basher
09/27/2019, 9:24 PMrusshwolf
09/27/2019, 11:29 PMbasher
09/28/2019, 12:22 AM