Re-run Spring Boot Configuration Annotation Processor to update generated metadata

JavaSpringMavenIntellij Idea

Java Problem Overview


I've added:

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

to my pom.xml per intellij's request/warning.

Now I'm seeing "Re-run Spring Boot Configuration Annotation Processor to update generated metadata".

How do I do what intellij is asking me to do?

This link, B.2 Generating your own meta-data using the annotation processor, does not have instructions.

Java Solutions


Solution 1 - Java

Following these instructions worked for me: http://www.mdoninger.de/2015/05/16/completion-for-custom-properties-in-spring-boot.html

That message about having to Re-run the Annotation Processor is a bit confusing as it appears it stays there all the time even if nothing has changed.

The key seems to be rebuilding the project after adding the required dependency, or after making any property changes. After doing that and going back to the YAML file, all my properties were now linked to the configuration classes.

You may need to click the 'Reimport All Maven Projects' button in the Maven pane as well to get the .yaml file view to recognise the links back to the corresponding Java class.

Solution 2 - Java

None of these options worked for me. I've found that the auto detection of annotation processors to be pretty flaky. I ended up creating a plugin section in the pom.xml file that explicitly sets the annotation processors that are used for the project. The advantage of this is that you don't need to rely on any IDE settings.

<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.7.0</version>
			<configuration>
				<compilerVersion>1.8</compilerVersion>
				<source>1.8</source>
				<target>1.8</target>
				<annotationProcessors>
                    <annotationProcessor>org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor</annotationProcessor>
					<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
					<annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
				</annotationProcessors>
			</configuration>
		</plugin>

Solution 3 - Java

None of the answers worked for me. If you just want to disable the message, go to Intellij Preferences -> Editor -> General -> Appearance, uncheck "Show Spring Boot metadata panel".

However, you can also live with that message, if it does not bother you too much, so to make sure you don't miss any other Spring Boot metadata messages you may be interested in.

Solution 4 - Java

You can enable annotation processors in IntelliJ via the following:

  1. Click on File
  2. Click on Settings
  3. In the little search box in the upper-left hand corner, search for "Annotation Processors"
  4. Check "Enable annotation processing"
  5. Click OK

Solution 5 - Java

I had the same issue. The problem is that the Spring Boot annotation processor generates the spring-configuration-metadata.json file inside your /target/classes/META-INF folder.

If you happen to have ignored this folder in IntelliJ like me (because what the heck, who cares about classes files?), the file won't be indexed by your IDE. Therefore, no completion, and the annoying message.

Just remove target from the ignore files/folders list, located in Settings > Editor > File Types > Ignore files and folders.

Solution 6 - Java

For me, other answers didn't work. I had to go to open Files and do Invalidate caches and restart on Intellij. After that, everything worked fine again.

Solution 7 - Java

  1. Include a dependency on spring-boot-configuration-processor
  2. Click "Reimport All Maven Projects" in the Maven pane of IDEA
  3. Rebuild project

Solution 8 - Java

I just needed

@EnableConfigurationProperties({MY_PROPS_CLASS.class})

in Main Application class and it helped me to resolve this issue

Solution 9 - Java

Having included a dependency on spring-boot-configuration-processor in build.gradle:

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:2.4.1"

the only thing that worked for me, besides invalidating caches of IntelliJ and restarting, is

  1. Refresh button in side panel Reload All Gradle Projects
  2. Gradle task Clean
  3. Gradle task Build

Solution 10 - Java

I had a similar issue using Gradle and Kotlin. You should modify the build.gradle.kts file to include the following:

//build.gradle.kts
plugins {
  // ...
  kotlin("kapt") version "1.5.31"
}


dependencies {
  // ...

  kapt("org.springframework.boot:spring-boot-configuration-processor")
}

Then, to generate the annotations:

./gradlew kaptKotlin

References: https://spring.io/guides/tutorials/spring-boot-kotlin/#_configuration_properties

Solution 11 - Java

I had the same problem. In my case I was missing the spring-boot-maven-plugin.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

as well as the @Data Lombok annotation

@Configuration
@ConfigurationProperties("logging.web")
@Data
public class LoggingWebConfiguration {
// ...
}

Obviously you can also just create the getter/setters yourself.

Then you must also remember to re-import and re-compile your project.

Solution 12 - Java

None of the above worked in my case, but brought me close. In the end explicitly defining all required annotationProcessors in the maven-compiler-plugin solved it for me. In my case this was: Spring-Boot + Lombok + MapStruct

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
      <annotationProcessorPaths>
        <annotationProcessorPath>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-configuration-processor</artifactId>
          <version>${spring-boot-configuration-processor.version}</version>
        </annotationProcessorPath>
        <annotationProcessorPath>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>${lombok.version}</version>
        </annotationProcessorPath>
        <annotationProcessorPath>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>${mapstruct.version}</version>
        </annotationProcessorPath>
      </annotationProcessorPaths>
    </configuration>
  </plugin>

Before that I always got some warnings in the Class + in the application.properties some properties were marked as "unusued", even when they were defined in a class with @ConfigurationProperties

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric FrancisView Question on Stackoverflow
Solution 1 - JavaPatrick HerreraView Answer on Stackoverflow
Solution 2 - JavaJason TuranView Answer on Stackoverflow
Solution 3 - JavaLorenzo PolidoriView Answer on Stackoverflow
Solution 4 - JavaBrandon SView Answer on Stackoverflow
Solution 5 - JavaDeathtinyView Answer on Stackoverflow
Solution 6 - JavaSep GHView Answer on Stackoverflow
Solution 7 - JavatimomeinenView Answer on Stackoverflow
Solution 8 - JavariprealView Answer on Stackoverflow
Solution 9 - JavafachexotView Answer on Stackoverflow
Solution 10 - JavaJoão Verissimo RibeiroView Answer on Stackoverflow
Solution 11 - JavaJasper CitiView Answer on Stackoverflow
Solution 12 - JavaMario BView Answer on Stackoverflow