halirutan
halirutan

Reputation: 4341

Gradle: use file contents as property value

Assume I have a description in a file and I want to use the file contents for setting a property in Gradle. What I'm currently doing is something like that

String myChangeNotes = file('resources/META-INF/change-notes.html').text
String myDescription = file('resources/META-INF/description.html').text

patchPluginXml {
    changeNotes = myChangeNotes
    pluginDescription = myDescription
}

It works, but it does not reload the file when it changes. I guess I have to make a task that has as input the two HTML files so that Gradle knows when they change, but I'm not sure how to proceed.

How would I do it so that the changeNotes and pluginDescription properties of patchPluginXml are reloaded each time the files change on disk?

Upvotes: 0

Views: 131

Answers (1)

Vampire
Vampire

Reputation: 38734

You already have a task that has the contents of the files as input. As you read the files in the configuration phase, they are always read freshly when you start your build. The changeNotes and pluginDescription fields of the patchPluginXml task (if we talk about the gradle-intellij plugin) are defined as inputs, so if their value changes, the task will be re-run. So everything seems to be set up correctly.

Upvotes: 1

Related Questions