Search code examples
mavenintellij-ideacode-generation

define additional source directory in maven


I generate Java sources from a wsdl file. These sources are not under version control (but the wsdl is). We use the cxf-codegen-plugin in maven and the generated classes are generated in <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>.

This works all fine in maven.

I have to define this directory as addition source directory in Intelij Idea. (targetis normaly excluded).

But every time I re-import the maven project into InteliJ Idea (due to pom changes), I have to manually edit the project structure in Idea and redefine the addition source directory.

Is there any way I can either define this aditional source directory in maven, so Idea picks it up on reload, or tell Idea not to forget the manual source directoy definition?


Solution

  • This case is described in the IntelliJ IDEA Maven FAQ, Generated Sources section:

    Specify the directory of your source root when you reimport a project.
    You can select one of the following options:

    • Detect automatically This is a default option. When you select this option, IntelliJ IDEA automatically detects the location of the generated sources. IntelliJ IDEA also detects which directory to mark as a source root. However, IntelliJ IDEA searches for the generated sources only in target/generated-sources and target/generated-sources/* directories.

    • target/generated-sources This option enables you to mark the directory as source root manually.

    • subdirectories of "target/generated-sources" This option enables you to mark a subdirectory as a source root manually.

    • Don't detect This option lets you skip the detection process.