I have some data in my gradle.properties
file:
appVersion=1.4.31
appGroup=com.business
appName=projectName
I want to be able to access them in a .java
project. I am attempting to access the variable like this:
@Value("${appVersion}")
private int version;
However, when I try to run the application from the main class, I get the following error:
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'appVersion' in value "${appVersion}"
Which shows that it can't find the correct variable.
Attempts at solving the problem
Adding a @propertySource
Annotation
I have tried adding this to the main class
@PropertySource(value = "file:build.gradle", ignoreResourceNotFound = true)
which was unsuccessful.
Making changes in build.gradle
I attempted the following, taken from this StackOverflow answer:
processResources {
filesMatching('application.properties'){
expand(gradle.properties)
}
}
Which was also unsuccessful.
This answer below
I did what was said in this answer (I had to add an application.properties
file) and I got this error message:
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Circular placeholder reference 'appVersion' in property definitions
I thought that it might be getting mixed up with using the same names (appVersion = appVersion), so I changed the application.properties line to
version=${appVersion}
And then in my .java
file, I changed the line to:
@Value("${version}")
private String version;
And got the error:
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'appVersion' in value "${appVersion}"