Autowiring BuildProperties bean from Gradle - NoSuchBeanDefinitionException : <p>I am trying to obtain the version in my Java application from the Gradle build file. I am following the instructions here;</p>

<p><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html" rel="noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html</a></p>

<p><strong>build.gradle</strong></p>

<pre><code>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')
 }
</code></pre>

<p>After building with gradle the <code>build-info.properties</code> file is present in build/resources/main/META-INF/build-info.properties</p>

<p>In my <code>@RestController</code> I am trying to autowire the build properties bean</p>

<pre><code>@Autowired
private BuildProperties buildProperties;
</code></pre>

<p>I am getting the following error;</p>

<pre><code>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
</code></pre>

<p>I would assume that the <code>BuildProperties</code> bean is automatically created when the build-info.properties is present. It does not seem to be the case.</p>
