Gradle + Spring facet configuration

I've been looking for examples of having Gradle automatically configure the Spring facet when importing into IDEA and I haven't seen one, so I finally sat down and did it.

One annoying part is that the set of Spring configuration files (i.e. classes annotated with @Configuration) and the XML application context files need to be specified when Gradle is creating the project (IML) file. I'd rather not hardcode the list of files in my Gradle build script or some other config file.

Short of having Gradle search for XML files based on file name patterns within the resources of the project and using something like Spring's ClassPathScanningCandidateComponentProvider in the build script to scan for classes annotated with @Configuration on a limited classpath, does anyone have other approaches to solving this?

I was really hoping whatever utility classes IDEA itself uses would be made available so that a custom Gradle plugin (or the official IDEA plugin for Gradle) could do the scanning as part of the Gradle build...

Comment actions Permalink


If I understand correctly, you want to setup a Spring facet/fileset automatically during Gradle import via a dedicated IntelliJ plugin.

You can use Spring OpenAPI to provide an implicit fileset via extension point com.intellij.spring.SpringModelProvider which then contains all your wanted configuration files.

Obtaining all Spring XML config files can be achieved using DOM

DomService.getInstance().getFileElements(Beans.class, project, scope)

@Configuration classes can be queried using


Please see for a general overview of Spring OpenAPI.

Comment actions Permalink

I haven't really looked into IntelliJ plugins but that sounds like a good solution.

Currently folks I work with get the notification popup that IDEA has detected new/unconfigured Spring config files every time they launch IDEA so most end up disabling the feature. I was hoping to ensure that the facet was automatically (and always) configured for them.

The PoC approach I had taken was to apply Gradle's IDEA plugin to the project and modify the generated XML for the module to include the Spring facet + configuration files so that when the project was imported – initially or automatically as Gradle files change & get refreshed – the Spring facet would remain configured. The downside was that I either have to duplicate the scanning performed by IntelliJ or hardcode files into the Gradle build file.

Comment actions Permalink

Please note that modifying the .IML is a solution that might break any time we change the storage format for Spring facet configuration data.

Automatic configuration of the facet is not really possible unless there is deterministic way of setting up such contexts according to specific rules (as it's done for Spring MVC via web.xml config).


Please sign in to leave a comment.