Skip to content

Commit 5f04ad6

Browse files
Add since attribute to uses of DeprecatedConfigurationProperty
Add an architecture rule to ensure that all usages of `@DeprecatedConfigurationProperty` in the Spring Boot codebase include the `since` attribute. Add the `since` attribute to the few places where it was not already included.
1 parent 0ca8f6d commit 5f04ad6

File tree

4 files changed

+20
-3
lines changed
  • buildSrc/src/main/java/org/springframework/boot/build/architecture
  • spring-boot-project
    • spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway
    • spring-boot-docs/src/main
      • java/org/springframework/boot/docs/appendix/configurationmetadata/format/property
      • kotlin/org/springframework/boot/docs/appendix/configurationmetadata/format/property

4 files changed

+20
-3
lines changed

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static List<ArchRule> standard() {
9898
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
9999
rules.add(conditionsShouldNotBePublic());
100100
rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic());
101+
rules.add(allDeprecatedConfigurationPropertiesShouldIncludeSince());
101102
return List.copyOf(rules);
102103
}
103104

@@ -348,6 +349,22 @@ private static ArchRule allConfigurationPropertiesBindingBeanMethodsShouldBeStat
348349
.allowEmptyShould(true);
349350
}
350351

352+
private static ArchRule allDeprecatedConfigurationPropertiesShouldIncludeSince() {
353+
return methodsThatAreAnnotatedWith(
354+
"org.springframework.boot.context.properties.DeprecatedConfigurationProperty")
355+
.should(check("include a non-empty 'since' attribute", (method, events) -> {
356+
JavaAnnotation<JavaMethod> annotation = method
357+
.getAnnotationOfType("org.springframework.boot.context.properties.DeprecatedConfigurationProperty");
358+
Map<String, Object> properties = annotation.getProperties();
359+
Object since = properties.get("since");
360+
if (!(since instanceof String) || ((String) since).isEmpty()) {
361+
addViolation(events, method, annotation.getDescription()
362+
+ " should include a non-empty 'since' attribute of @DeprecatedConfigurationProperty");
363+
}
364+
}))
365+
.allowEmptyShould(true);
366+
}
367+
351368
private static boolean containsOnlySingleType(JavaType[] types, JavaType type) {
352369
return types.length == 1 && type.equals(types[0]);
353370
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public void setOutputQueryResults(Boolean outputQueryResults) {
794794
this.outputQueryResults = outputQueryResults;
795795
}
796796

797-
@DeprecatedConfigurationProperty(replacement = "spring.flyway.sqlserver.kerberos-login-file")
797+
@DeprecatedConfigurationProperty(replacement = "spring.flyway.sqlserver.kerberos-login-file", since = "3.2.0")
798798
@Deprecated(since = "3.2.0", forRemoval = true)
799799
public String getSqlServerKerberosLoginFile() {
800800
return getSqlserver().getKerberosLoginFile();

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/appendix/configurationmetadata/format/property/MyProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void setName(String name) {
3333
}
3434

3535
@Deprecated
36-
@DeprecatedConfigurationProperty(replacement = "my.app.name")
36+
@DeprecatedConfigurationProperty(replacement = "my.app.name", since = "1.2.0")
3737
public String getTarget() {
3838
return this.name;
3939
}

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/appendix/configurationmetadata/format/property/MyProperties.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.DeprecatedConfigurationProper
2323
class MyProperties(val name: String?) {
2424

2525
var target: String? = null
26-
@Deprecated("") @DeprecatedConfigurationProperty(replacement = "my.app.name") get
26+
@Deprecated("") @DeprecatedConfigurationProperty(replacement = "my.app.name", since = "1.2.0") get
2727
@Deprecated("") set
2828

2929
}

0 commit comments

Comments
 (0)