Can I configure IntelliJ to autocomplete spring boot properties in a git repo

Viewed 607

I've got a multi-module maven project (monorepo) with a directory for config (used by the spring cloud config server), and I'm hoping to configure IntelliJ to autocomplete the properties using the spring-boot-configuration-processor.

enter image description here

The metadata (additional-spring-configuration-metadata.json) is correctly generated in the microservices modules, but I can't figure out how to configure Intellij to autocomplete in the directory with the externalised config. Is this possible?

enter image description here

I've tried making the plain config directory a maven module, and adding spring facet.

2 Answers

The "minimally invasive way" I figured out is the following: Put a [configurationName].iml file with the following content

<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="Spring" name="Spring">
      <configuration />
    </facet>
  </component>
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
    <output url="file://$MODULE_DIR$/target/classes" />
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/target" />
    </content>
    <orderEntry type="library" scope="PROVIDED" name="Maven: com.my.component:Major.Minor.Patch-SNAPSHOT" level="project" />
    ...
    <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.6.4" level="project" />
    <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.6.4" level="project" />
    <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.6.4" level="project" />
    ...
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

in the yml-file's folder. It is a stripped down version of an IntelliJ project file that should reference all dependencies in your project that ship with a

*spring-configuration-metadata.json

They can be identified using a file search for

spring-configuration-metadata.json

in the (non config but code) project choosing to search in "all places".

enter image description here

Use "Open in find tool window" (rightmost corner in the search dialogue) to facilitate copying the file path into the clipboard for editing and extraction.

This approach has the disadvantage to out-date if the dependencies change but since the spring-configuration-metadata.json does not update that often and is not mission critical, for me that's acceptable.

A "These modules have been removed from Maven structure" popup might apprear, do not opt for removing the modules from the project too, this would break the auto-suggest.

Related