The above ant target executes a shell script and writes the output of the script to a file. This file is then bundled as part of a war.
How does one achieve the same effect in Gradle when using Kotlin DSL? I’m guessing that an Exec task would be the way to go. However I’m not able to find any examples. FWIW I’m already using the built-in war plugin to create the war file.
I get the feeling that you are writing to the same output directory as the “processResources” task. Each task should use a separate output directory so that up-to-date checks /task skipping can work correctly.
Something like:
task gitLog {
ext.logDir = file("$buildDir/gitLog")
outputs.dir logDir
doLast {
file("$logDir/commit.json").withOutputStream {...}
}
}
processResources {
from gitLog // adds the folder and also adds a task dependency
}
I’ve modified processResources and it is working fine. (How) can I add multiple from clauses to processResources? Some of these have differing into clauses. Is there an idiom for this?
To give more context, I want to add some custom information to the war file produced later.
can I add multiple from clauses to processResources ? Some of these have differing into clauses. Is there an idiom for this
You can use Copy.with(CopySpec). Eg:
processResources {
with(copySpec {
from 'a'
into 'b'
})
with(copySpec {
from 'c'
into 'd'
})
}
The add folder works; however I have to explicitly declare the task dependency. Am I missing something
Yes, you are. My example uses from(Task) whereas yours from(String). Gradle will automatically add task dependencies for FileCollection backed by a task. When using string or File you’ll need to explicitly add the Task dependency