javagradlebuild.gradle.class-filegradle.properties

How to get value from gradle.properties in .class file at the time of build


I would like to get a property value from Gradle.properties in Java class. In Java, the value should be replaced at build time, and in the .jar(.class) file the value will come but not in a .java file. So that we can change the value directly in gradle.properties and no need to change the code. Is it possible to achieve?


Solution

  • It would be easier to answer if you told your specific use case. Also it would help to know your application, for example is it a Spring (Boot) app? In that case it would probably make more sense to use Spring Profiles for that.

    Anyway, here is a possible solution: