BAEL-5027: Use BuildProperties bean for getting build information (#13794)

Co-authored-by: Tapan Avasthi <tavasthi@Tapans-MacBook-Air.local>
This commit is contained in:
Tapan Avasthi 2023-04-11 04:26:04 +05:30 committed by GitHub
parent 42dff48c7d
commit e8d8611e6e
2 changed files with 51 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-properties</artifactId>
<version>0.0.1-SNAPSHOT</version>
@ -74,6 +74,25 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<java.version>${java.version}</java.version>
<description>${project.description}</description>
<custom.value>123</custom.value>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>

View File

@ -0,0 +1,30 @@
package com.baeldung.buildproperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class BuildPropertiesUnitTest {
@Autowired
private BuildProperties buildProperties;
@Test
void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() {
Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact());
Assertions.assertEquals("com.baeldung.spring-boot-modules", buildProperties.getGroup());
Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion());
}
@Test
void givenBuildPropertiesBean_WhenFetchCustomBuildProprties_ThenGetValidValues() {
Assertions.assertEquals("123", buildProperties.get("custom.value"));
Assertions.assertNotNull(buildProperties.get("java.version"));
Assertions.assertEquals("Spring Boot Properties Module", buildProperties.get("description"));
}
}