I need to make my gradle plugin provide a flag to ...
# community-support
j
I need to make my gradle plugin provide a flag to my compiled library that will read it while executing the project... would setting and reading a system property be the best way of doing it ? Something like in the plugin
Copy code
systemProperty("SCREENSHOT_TESTS_REFERENCE_RUN", true)
in the library
Copy code
System.getProperty("SCREENSHOT_TESTS_REFERENCE_RUN")
        ?.toBooleanStrictOrNull() == true
v
Assuming the "compiled library" is then used by other consumers and not from the build that the plugin applies and there needs the value, using a system property is not nearly anywhere near appropriate, as it would not be set unless the consumer of the library would also set the system property in his process where he uses your library. If you want such a setting hard-coded in your library, you have to hard-code it into the library. For example in a properties file with a placeholder where you use for example
expand
on the
processResources
task to fill in the placeholder with the value you want to have at runtime and then reading that file. If doing so, don't forget to restrict the replacing on the relevant files and setting a
filteringCharset
.
j
The plugin and the lib should work together and it is just an internal lib for my company... If I understood you well, using
processResources
is basically writting/reading a file, right ?
v
processResources
basically is a task that copies the resources from
src/main/resources
into a folder in the build directory. And that you can configure to for example fill in placeholders in those copied files to have build-time values at runtime.