Is it possible to keep a directory marked as a source root after it has been deleted/recreated ?

I have a generated sources in my target dir.

After each maven clean this dir is trashed and re-created.
Then I have to tell to Intellij that the freshly created dir is still a source dir.

It is annoying, so is there any way to have intellij to remember that this dir was a source dir ?

5 comments

For a maven based project, IDEA determines the source directories using the directories specified by the <sourceDirectory> and <resources> elements in the pom file. Make sure your generated sources directory is listed as a resource in your POM:

    <build>
        . . .
        <resources>
            <resource>
                <directory>${project.build.directory}/generated</directory>
            </resource>
        </resources>
        . . .
    </build>

0

Hi, Guillaume
IPlease, check iml file - you can  put sources path in that file directly.

regards, Alex

0

Hi Alexander,

Unfortunately, this solution is not working: once the generated source dir is deleted, then the .iml file is modified and I lost this dir as a source until I explicitely tell to Ideal that it is a source dir...

Thanks for this suggestion.

0

This is working, but since this is a grails project, the introduced pom file is now conflicting with the grails goal "maven-install" I'm using to package and distribute the application.
I can not introduce this 'fake' pom file (we are a team working on the project, and this pom will be confusing)
I have tried to add a fake pom elsewhere in the application but this confused Intellij: grails project was transformed into a maven project with wrong root dir...

So I can not use this solution :_|

0

Settings > Project Settings > Maven > Importing > Keep source and test folders on reimport

Boom.

0

Please sign in to leave a comment.