title: how to capture Build Info using Gradle and Spring Boot
body: <p>I am trying to get access to build info values such as <code>version</code> in my Java main application using Spring Boot and Gradle.</p>
  
  <p>I can't find any documentation / examples of how to configure the </p>
  
  <ul>
  <li><code>build.gradle</code></li>
  <li><code>application.yml</code> (if required)</li>
  <li><code>Java main class</code></li>
  </ul>
  
  <p>could someone please help with a small code example for the above files.</p>
  
  <p>In my <code>build.gradle</code> file I will have the <code>version</code> entry, so how to get this into Java main class using Spring Boot and Gradle.</p>
  
  <h2>build.gradle</h2>
  
  <pre><code>version=0.0.1-SNAPSHOT
  </code></pre>
  
  <p>I've tried adding</p>
  
  <h2>build.gradle</h2>
  
  <pre><code>apply plugin: 'org.springframework.boot'
  
  springBoot {    
      buildInfo() 
  }
  </code></pre>
  
  <p>but the <code>buildInfo()</code> isn't recognised as a keyword in Intellij</p>
  
  <p>In my Java main class I have the following:</p>
  
  <pre><code>public class MyExampleApplication implements CommandLineRunner {
      @Autowired
      private ApplicationContext context;
  
      public static void main(String[] args) {
          SpringApplication.run(MyExampleApplication.class, args);
      }
  
      @Override
      public void run(String[] args) throws Exception{
          Environment env = (Environment) context.getBean("environment");
          displayInfo(env);
      }
  
      private static void displayInfo(Environment env) {
         log.info("build version is &lt;" + env.getProperty("version")     
      }
  </code></pre>
  
  <p>But when I run this - the output from <code>env.getProperty("version")</code> is showing as <code>null</code>.</p>