Woodchuck
Woodchuck

Reputation: 4454

Custom properties in Spring Boot project using Gradle

In my Spring Boot project (1.5.6.RELEASE) that I build using gradle, I want to include some custom properties. The approach laid out in the documentation does not seem to work (on build, I get: Could not set unknown property 'additional' for task ':properties' of type org.gradle.api.tasks.diagnostics.PropertyReportTask.):

springBoot {
    buildInfo {
        properties {
            additional = [
                'a': 'alpha',
                'b': 'bravo'
            ]
        }
    }
}

Luckily this approach, which I found here, does work for me (no compile error and I'm then able to access the property from my code):

springBoot{
    buildInfo {
        additionalProperties = [
            'testpropertykey': 'testpropertyvalue'
        ]
    }
}

But, since the former is the "officially" documented approach, I would prefer to take that approach. How would I get the former approach to work? I assume I'm missing something - unless the documentation is wrong or maybe this changed from Spring Boot 1.5.6.RELEASE.

Upvotes: 3

Views: 1885

Answers (1)

Cisco
Cisco

Reputation: 23052

The docs you linked are for the current version of the plugin which aligns with the current GA version of Spring Boot: 2.1.7

Version 1.5.x of the plugin does have a additionalProperties field: https://github.com/spring-projects/spring-boot/blob/1.5.x/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/buildinfo/BuildInfo.java#L66

The 2.1.x version does not and you use properties instead: https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java#L45

Suggest you migrate/upgrade to Spring Boot 2.1.x or 2.2.x when that is released soon since 1.5.x has already reached EOL: https://spring.io/blog/2018/07/30/spring-boot-1-x-eol-aug-1st-2019

Upvotes: 6

Related Questions