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?
How to get value from gradle.properties in .class file at the time of build
4.5k Views Asked by Sumanta Biswas At
1
There are 1 best solutions below
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in GRADLE
- Gradle. Detect dependencies problems
- Gradle Duplicate Entry
- Creating distribution with repackaged spring boot jar using gradle application plugin
- LinkageError after upgrading dropwizard to 0.8.1
- Android Studio unable to run the project
- Add JVM args to spring boot application
- How do I know what is available in minSdkVersion in Android Studio?
- Gradle: Override transitive dependency by version classifier
- gradle get System environment variables
- Why does Eclipse want to download a previous version of Gradle when I already have a later version installed?
- Gradle project sync failed - Gradle DSL method not found: android()
- Use thymeleaf template for some pages and rest for some for building gradle project
- 'Provided' dependency in Gradle
- Invalid Gradle JDK configuration found
- Does Android Studio use Gradle Daemon?
Related Questions in BUILD.GRADLE
- determine if it is jenkins environment inside gradle
- Code Path per Flavor in Android Gradle
- Customised doc generation in Javadoc using Gradle
- Failing the build.gradle for serenity plugin
- Android Crashlytics ndk; values of NdkOut and NdkLibsOut in build.gradle
- Android Studio Execution Failed for task ':app:dexDebug' Error code: 1
- Aidl is missing error
- Gradle Build Failure
- Android: Execution failed for task ':app:processDebugResources'
- Why can't Gradle see this Maven co-ordinate in the local m2 repository?
- Gradle project refresh failed in Android Studio 1.2.1.1
- How to solve Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 2
- Android Studio : UNEXPECTED TOP-LEVEL EXCEPTION:
- Gradle: Check a file exist without file name
- Android Studio ——How can I modify one Class's field before compile by build.gradle
Related Questions in .CLASS-FILE
- AOT compiling with jRuby to obfuscate Rails code
- symbol not found: static method in abstract class (BCEL)
- Is it possible to encrypt a java class file?
- output of javap command
- Create .class files from the command line with package dependencies
- Do I need to restart Tomcat when changing .class files
- Why are my bin directories not getting filled with .class files?
- Javac doesn't recompile referenced classes after changes in referenced java source file
- how to manually read the java bytecode for understanding purposes only?
- java -setting the location of manually compiled class files
- why every class file starts with "Êþº¾ "
- Android Studio & Gradle: Adding external classes to build path
- easy way to find references to other classes in class file
- Inserting magic number into class files
- How does one add source to a .class file on eclipse?
Related Questions in GRADLE.PROPERTIES
- viewbinding: android.defaults.buildfeatures vs. buildFeatures{}?
- Could not get unknown property 'project' for settings
- Changing org.gradle.jvmargs Value
- Unable to get gradle.properties when running bootRun through Docker
- Running parallel gradle jobs - busy Daemons could not be reused
- Gradle build fails with Out of Memory: Java heap space error
- How do you access gradle.ext properties in Plugin Java source code?
- gradle.properties special characters in proxy password
- build.gradle file does not find a property from the gradle.properties file
- Intershop | dB migrate
- Passing parameter value from properties file to Jenkins
- Adding permission for ml-data folder using ml-gradle
- java.io.InvalidClassException: org.jetbrains.kotlin.incremental.IncrementalModuleInfo
- build.gradle file does not access to gradle.properties
- How to get value from gradle.properties in .class file at the time of build
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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:
Create a properties file and put it in your resources folder. Define a placeholder, that gradle can replace. For example file "myapp.properties"
Add the token (the text between the '@'s) to your gradle.properties:
Make the build.gradle replace the token with the value from gradle.properties by configuring the processResources task:
}
At runtime load the value from the properties file: