I use the spring-boot-configuration-processor jar to generate configuration metadata files.

According to doc

The annotation processor applies a number of heuristics to extract the default value from the source model. Default values have to be provided statically.

But the property attribute defaultValue couldn't be able to generate in metadata after using IntelliJ IDEA's Build or Run. And could be generated by using Maven compile.

Local Environment: - JDK 1.8.0-291 - Maven 3.8.1 - IntelliJ IDEA Ultimate 2021.1.3 - spring-boot-configuration-processor 2.5.4

Didn't test in the other versions of IntelliJ IDEA. So I don't know if it's an IDEA's bug.

Class:

@Component
@ConfigurationProperties(prefix = AmazonProperties.PREFIX)
public class AmazonProperties {

    public static final String PREFIX = "amazon";

    /**
     * Amazon AccessKey
     */
    private String accessKey = "defaultKey";

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }
}

Screenshot below SpringBoot default values are not detected when generating metadata from IntelliJ IDEA SpringBoot default values are not detected when generating metadata from IntelliJ IDEA

Comment From: snicoll

property attribute defaultValue couldn't be able to generate in metadata after using IntelliJ IDEA's Build or Run.

I am not sure what we ca do about that. What JDK are you using in Intellij IDEA? Is it the same than what you use to build the project with Maven?

Comment From: nidoze

property attribute defaultValue couldn't be able to generate in metadata after using IntelliJ IDEA's Build or Run.

I am not sure what we ca do about that. What JDK are you using in Intellij IDEA? Is it the same than what you use to build the project with Maven?

I use JDK1.8.0.291 in Intellij IDEA, it had been verified from Build Output, it showed "javac 1.8.0_291 was used to compile java sources " It is the same version of JDK when building the project with Maven. I compile the project in the command line using "mvn compile" and "defaultValue" could be generated. I search Intellij IDEA help doc and chose "delegate IDE build/run actions to Maven" in IDEA's setting, then build the project by IDEA's Build, and "defaultValue" come back. It's a Maven project, I realize I should compile it by Maven preferential, I think that may be IDEA's problem. Thanks for your reply very much!

Comment From: snicoll

@voyager2universe thanks for the feedback. No, it should work in the IDE as well. It breaks for me as well and I believe this might be a recent change in IntelliJ IDEA. I've reported the problem to them.

Closing in favor of https://youtrack.jetbrains.com/issue/IDEA-276648