I'd like to create a class to help me loading different types of properties (local.properties
, gradle.properties
, $GRADLE_HOME/gradle.properties
, environment variables, system properties, and custom properties files (maybe in other formats like yml
, xml
, etc.).
Also, I'd like to use this in my buildSrc/build.gradle.kts
, settings.gradle.kts
, and build.gradle.kts
.
Please consider that we are using Gradle 6.+
.
A simple implementation of this class would be (the full implementation would be a lot of more powerful):
plugins/properties/build.gradle.kts:
package com.example
object Properties {
val environmentVariables = System.getenv()
}
How can we successfully import this Properties
class in all of those files (buildSrc/build.gradle.kts
, settings.gradle.kts
, build.gradle.kts
) and use it from there? Something like:
println(com.example.Properties.environmentVariables["my.property"])
Can we do that creating this class inside of a plugin and applying it from there? Without pre-compiling and releasing the plugin? Maybe something like:
apply("plugins/properties/build.gradle.kts")
How would it be a minimal implementation for this?
I tried different approaches but I'm not being able to find a way that work with those 3 files altogether.