18

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?

2
  • 2
    Did you check wiki.jetbrains.net/intellij/Maven_FAQ ? Commented May 24, 2012 at 12:49
  • @CrazyCoder Should have checked their wiki first. "generated-sources" did the trick. Thanks. Can you post it as an answer, so I can accept it? Commented May 24, 2012 at 13:12

4 Answers 4

18

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.

Sign up to request clarification or add additional context in comments.

Comments

5

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> 

1 Comment

this does generate the sources outside of the target folder and I can build the project. Unfortunately, Idea still need manual definition of this additional folder, hence my problem remains.
1

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.

1 Comment

thanks. Idea does keep this change after pom reload. Java files are recognized as such. Unfortunately, Idea does not resolve class references to files in such a directory. Strange, I will investigate furter
0

When facing this situation it may simply be the case that Intellij is not aware of any updates to the source folder. Right clicking the project, selecting Maven, and then "Generate source and update folders" may provide the refresh you need.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.