简体   繁体   中英

Cannot generate Spring Boot configuration metadata with gradle

I want to generate Spring Boot configuration metadata, with this way:

configuration-metadata-annotation-processor-setup

In maven, its ok:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

But in gradle, no generated:

dependencies {
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}

There is same problem with spring-boot-configuration-processor , maven is OK but gradle not.

Plugins I used is java or org.jetbrains.kotlin.jvm , not org.springframework.boot , but I don't think here is the problem (with plugin org.springframework.boot , the problem still exists).

Along with the steps you have mentioned you also need to add a class mapping. Something like below.

import lombok.Data;    
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "my.props")
@Data
public class MyProperties {

  /**
   * Prop1 description.
   */
   private String prop1;

   /**
   * Prop2 description.
   */
   private String prop2;
}

It's okay to add a class without props but it's needed.

Sample content of resources/META-INF/additional-spring-configuration-metadata.json

{
   "properties": [
      {
         "name": "my.props.prop1",
         "type": "java.lang.String",
         "description": "Prop1 description",
         "defaultValue": "property 1"
      }
    ]
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM