To pin source folders in Maven-based project.

I am a user of IntelliJ IDEA Ultimate Edition 10.5.4
I work on big Maven project that has many modules that use codegeneration. This mean that modules contain several source folders that are not recognized by IDEA (at least in my curly hands) I guess due to original names, for example ${basedir}/driver-generated-sources. To work in IDEA, I manually mark 9 folders as source folders. Also I change module and artifact versions from time to time, and IDEA erases source folder marks, so I forced to set them again. Some questions:

1) Is it possible to bind Action "Mark as a source folder to some key" ? - I forced to use mouse every time
2) Is it possible to specify any patterns for folder names to help IDEA recognize that folder is a source folder?
3) Is it possible to pin marks or source folders, so that disallow IDEA to unmark source folders itself?

Comment actions Permalink

Some additional comments.

1) Action "Mark Directory As" ----> "Source Root" requires pass through two menues and there are no hot keys. It is very boring when you need to mark dozen folders in project with mouse clicks

2) May be it is possible somehow to help IDEA to recognize generated source folders - for example adding declarations to pom.xml files, or specifying a list of names that belong to source folders.
I use branches of same project, that slightly different, but have same set of generated source folders

3) I am using IDEA since 10.0.x, and initially there were no such problem. Now when I change version, say from 10-SNAPSHOT to 11-SNAPSHOT and execute mvn clean install, all marks of source folders disappear.

Comment actions Permalink

You can map Mark as Source to a hotkey if desired. File > Settings > IDE Settings > Keymap. The action you want is Other > Source Root. (You can just search for "Source Root").

However, my recomendation to solve your issue would be to place the needed configuration in your maven POM(s). Just list your generated source directory in the <project></build><resources> element.   (Since you are changing the default, you will of course have to also list the standard "resources" directory.)


If you do that, and than reimport the maven project (using the reimport button on the maven tool window) IDEA will automatically add the directories as source directories and you will not need to keep adding them back when IDEA reimports the POMs when you make other changes.


Please sign in to leave a comment.