I am trying to obtain the version in my Java application from the Gradle build file. I am following the instructions here;
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:1.5.7.RELEASE")
}
}
project.version = '0.1.0'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
springBoot {
buildInfo()
}
jar {
baseName = 'ci-backend'
}
war {
baseName = 'ci-backend'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework:spring-jdbc")
compile("joda-time:joda-time")
compile("com.opencsv:opencsv:3.9")
compile("org.springframework.batch:spring-batch-core")
testCompile('org.springframework.boot:spring-boot-starter-test')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
}
After building with gradle the build-info.properties
file is present in build/resources/main/META-INF/build-info.properties
In my @RestController
I am trying to autowire the build properties bean
@Autowired
private BuildProperties buildProperties;
I am getting the following error;
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.info.BuildProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 41 more
I would assume that the BuildProperties
bean is automatically created when the build-info.properties is present. It does not seem to be the case.