I have issues with usage of build properties generated by spring-boot-maven-plugin, goal build-info. This goal does not generate build-info properties file to META-INF folder. For testing purposes I created clean project by Spring Initializr and added only the goal.
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.3.RELEASE</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Test class
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.stereotype.Component;
@Component
public class TestClass {
@Autowired
private BuildProperties buildProperties;
}
Error when compiled
Description:
Field buildProperties in com.example.demo.TestClass required a bean of type 'org.springframework.boot.info.BuildProperties' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
The following candidates were found but could not be injected:
- Bean method 'buildProperties' in 'ProjectInfoAutoConfiguration' not loaded because @ConditionalOnResource did not find resource '${spring.info.build.location:classpath:META-INF/build-info.properties}'
Comment From: snicoll
I created clean project by Spring Initializr and added only the goal.
That's not what I see. Why is spring-boot-starter
and the spring-boot-maven-plugin
pinned on a different version than the parent? Mixing different Spring Boot versions is not supported.
Rather than pasting all that code in text, please consider sharing an actual repo we can run. That's what we'll need to do anyway in order to reproduce the problem.
You haven't mentioned how you ran the app. Perhaps you ran it from your IDE and the plugin didn't have a chance to create the file?
Comment From: doublemcz
@snicoll Thank you for quick response, I have created the repo on https://github.com/doublemcz/springboot-23620 I also removed version specification from the child and it does the same thing.
Comment From: snicoll
Thanks for the sample. I've updated your description to remove the screenshot as the sample provides all the information that we need.
You have bound the build-info
goal execution to the package
phase so that the plugin is invoked prior to creating the jar of the project but after tests have ran. Invoking this plugin so late in the Maven lifecycle means it hasn't ran yet when the test runs. Maven has a phase for that called generate-resources
that is the default phase for the goal. I've removed <phase>package</phase>
from your sample and it works as expected.
If you have more questions, please follow-up on StackOverflow.
Comment From: doublemcz
@snicoll Hmm, that's strage. I also removed it and it still does the some thing :-/ Even If I specify explicity
Comment From: snicoll
@doublemcz please consider reviewing existing comments.
Perhaps you ran it from your IDE and the plugin didn't have a chance to create the file?
You can run the sample from the command line (mvn package
) and then hopefully see that the file has been created.
Comment From: rdp
Running mvn generate-resources
for me with that github creates file target/classes/META-INF/build-info.properties
for me, for what it's worth... :)
Comment From: orubel
This exact same thing is occurring in gradle. buildProperties are being generated in BOOT-INFO
Do all my build from a shell outside the IDE otuside of GUI so no outside influence. You can see code here: https://github.com/orubel/spring-boot-starter-beapi