Robert Elliot
03/10/2025, 5:44 PMRobert Elliot
03/10/2025, 5:45 PMval generatedResourceDir = layout.buildDirectory.dir("generated/resources")
sourceSets {
main {
resources.srcDir(generatedResourceDir)
}
}
tasks {
val setVersions by registering(Sync::class) {
from(layout.projectDirectory.dir("src/main/resource-templates"))
into(generatedResourceDir)
rename { fileName ->
fileName.replace("-template", "")
}
expand(
"GIT_HASH" to (System.getenv("GIT_HASH") ?: "local"),
"VERSION" to (System.getenv("VERSION") ?: "local"),
)
}
processResources {
dependsOn(setVersions)
}
}
Robert Elliot
03/10/2025, 5:46 PM"src/main"
- can I derive that somehow?
⢠hardcoding "generated/"
as it's a convention - can I derive it somehow?Philip W
03/10/2025, 5:46 PMsourceSets {
main {
resources.srcDir(tasks.setVersions)
}
}
Philip W
03/10/2025, 5:46 PMRobert Elliot
03/10/2025, 5:47 PMRobert Elliot
03/10/2025, 5:48 PMresources.srcDir(tasks.named("setVersions"))
Philip W
03/10/2025, 5:49 PMval setVersions by tasks.registering
and srcDir(setVersions)
laterThomas Broyer
03/10/2025, 5:49 PMsourceSets.configureEach
), then you could derive the main
from the source set, but that's it (and you should create a sourceset specific subdir inside your generated
).Robert Elliot
03/10/2025, 5:51 PMval setVersions by tasks.registering(Sync::class) {
from(layout.projectDirectory.dir("src/main/resource-templates"))
into(layout.buildDirectory.dir("generated/resources/from-templates"))
rename { fileName ->
fileName.replace("-template", "")
}
expand(
"GIT_HASH" to (System.getenv("GIT_HASH") ?: "local"),
"BUILD_NUMBER" to (System.getenv("BUILD_NUMBER") ?: "local"),
)
}
sourceSets {
main {
resources.srcDir(setVersions)
}
}
Robert Elliot
03/10/2025, 5:54 PMval templateResources by tasks.registering(Sync::class) {
from(layout.projectDirectory.dir("src/main/resource-templates"))
into(layout.buildDirectory.dir("generated/resources/from-templates"))
rename { fileName ->
fileName.removeSuffix("-template")
}
expand(System.getenv())
}
or is making the entire env available foolish?Robert Elliot
03/10/2025, 6:14 PMSystem.getenv()
and Groovy's SimpleTemplateEngine can't cope with missing env vars.Vampire
03/12/2025, 9:12 PMsrc/main/resources
directly and configure the processResources
task to do the expand
on the file.
Besides that, either way remember to also set the filtering charset, at least if input or output can ever contain non-ascii characters.Robert Elliot
03/13/2025, 9:35 AMRobert Elliot
03/13/2025, 9:37 AMVampire
03/13/2025, 2:49 PM