I have a project where I must set a certain SystemProperty before I begin my build task. However, the value for it varies every day.
As it stands, once the build task starts, I can no longer edit this property in a meaningful way (as the override gets ignored). As such, I’d like to do it beforehand.
To fetch the latest value for this property, I have code for an API call and will be extracting the value from the response.
This API call is within a Java class called “CallApi.java” within my “src/test/java” directory, under “com.test” package
I have it set up so that the function within CallApi.java returns a String, which I plan on setting as the value of the SystemProperty, before beginning execution.
My thought process is that if I can define a custom task to fetch the latest value for this property, then I can set it in the build.gradle directly using the “systemProperty” command as such:
systemProperty ‘placeholder’, customTask
then have Gradle execute the clean and build tasks.
Is this possible? If not, is there an alternate way to achieve this?
P.S.
I’ve tried this approach
import com.test.CallApi
task callApi {
doLast {
CallApi.getPropValue()
}
}
with the getPropValue() function returning mock String data, but the import statement doesn’t resolve
Sparsh Sondhi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.