Martmists
11/26/2024, 10:34 AMprocessResources {
val webpackTask = project(":site-frontend").tasks.getByName("webBrowser${if (project.production) "" else "DevelopmentExecutable"}Distribution")
// Goal: move from "<task_output>/path/to/font.ttf" to "<resources>/static/fonts/font.ttf>"
// Currently moves to "<resources>/static/fonts/path/to/font.ttf"
into("static/fonts") {
from(webpackTask) {
include("**/*.ttf")
}
}
}
All of the suggestions I can find online use FileTree, but that doesn't seem to work on task inputs.Vampire
11/26/2024, 10:52 AMsite-frontend
is configured before that project.
And even then, using getByName
you break task-configuration avoidance.
And even then, you miss the necessary task dependency and get either no files or stale files unless the task happens to accidentally run first.Vampire
11/26/2024, 10:52 AMVampire
11/26/2024, 10:55 AMThomas Broyer
11/26/2024, 10:56 AMeachFile { it.path = "" }
(unless you declare each file as an artifact published by the other project, in which case the problem would disappear, IIRC)Martmists
11/26/2024, 10:56 AMVampire
11/26/2024, 11:18 AMI don't think I understand those docs and how they apply to my situation (I'm exporting static files, not stuff that's on classpath configurations)No matter what you share. Never reach into another project's model, neither for configuring something, nor to retrieve some information or much worse task outputs. Actually one detail of what I said was wrong, the necessary task dependency should be there as you use the task as
from
argument, but everything else applies. If you need things from another project, use proper cross-project publication. Whether it is static files, or anything else does not really matter. And especially if it is about outputs of a task.
Just make sure you read the second link, in the 8.11 docs this section was lost somehow, I hope accidentally.
Other than that, what Thomas said. Either use for example eachFile
to set the path
or relativePath
, or the solution you found using file tree would probably be something like webpackTask.map { it.outputs.asFileTree.files }
. asFileTree
gives a file tree which means when before directories were output it resolves to the single files in them but still preserving the tree, i.e. relative path, and then using .files
flattens it out to only the files. The .map
makes sure you do not loose the task dependency. I wrote this from the top of my head, so it might not be 100% correct.Martmists
11/26/2024, 12:20 PMVampire
11/26/2024, 1:02 PMMartmists
11/26/2024, 1:05 PMVampire
11/26/2024, 1:10 PMMartmists
11/26/2024, 1:12 PMVampire
11/26/2024, 1:19 PMMartmists
11/28/2024, 12:00 PM// :site-frontend (provider)
artifacts {
add(sharedConfiguration.name, tasks.named("copyFonts"))
add(sharedConfiguration.name, tasks.named("copyIcons"))
add(sharedConfiguration.name, tasks.named("webBrowser${if (project.production) "" else "DevelopmentExecutable"}Distribution"))
}
// :site-backend (consumer)
tasks {
processResources {
into("static/js") {
from(sharedConfiguration) {
include("*.js")
include("*.wasm")
if (!production) {
include("*.map")
}
}
}
into("static/fonts") {
from(sharedConfiguration) {
eachFile {
path = "static/fonts/${path.split('/').last()}"
}
include("**/*.ttf")
}
}
into("static/icons") {
from(sharedConfiguration) {
eachFile {
path = "static/icons/${path.split('/').last()}"
}
include("**/*.svg")
}
}
}
}
This doesn't seem to copy any of the files from any of the 3 tasks added to artifacts.Vampire
11/28/2024, 4:45 PM