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?

3

Best Answer


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.

Take a look at the <add-source> build goal (see an example here)

Quote:

<plugin><groupId>org.codehaus.mojo</groupId><artifactId>build-helper-maven-plugin</artifactId><version>1.4</version><executions><execution><id>add-wsdl-source</id><phase>generate-sources</phase><goals><goal>add-source</goal></goals><configuration><sources><source>${basedir}/src-generated/src</source></sources></configuration><!-- [...] --></execution></executions></plugin>

You could define the (external) source directory as an dependency to your module. Project Structure -> Modules -> Depenencies. There you have to add a new JAR or Directory dependency.