18

In our project we are using jaxb2-maven-plugin to generate Java source code from XML Schema, which causes that our Maven module requires additional source code directory (in our case target/generated/main/java). Up to date I've been using Eclipse and maven-eclipse-plugin to import all the projects into Eclipse workspace. The plugin is (somehow) able to add the directory with generated source code automatically to Eclipse' .classpath file.

Recently I try to switch to (play with?) IntelliJ IDEA 9 (so I am a newbie in this environment) and I've noticed that additional source directory is not added during IDEA's importing process...

Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?

kopper
  • 2,676
  • 1
  • 16
  • 17

4 Answers4

28

The convention with Maven is to generate code in target/generated-sources/<tool>, for example target/generated-sources/jaxb2

Follow this convention and IDEA will add the folder as source folder (see IDEA-53198).

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 2
    But what if we need to set custom value? What if the directory is used also with another tool doing another phase? At this time, with Eclipse we don't have a problem, but with IDEA we do. – dmatej Jun 27 '13 at 10:47
  • @dmatej It is possible to set the location for generated sources. See 'Generated sources folders' option at http://www.jetbrains.com/idea/webhelp/maven-importing.html – ᄂ ᄀ Jul 06 '14 at 13:39
  • 1
    Be sure to use mvn idea:idea to ensure that this takes place after adding the mvn plugin module to your pom. – Robert Massaioli Jun 21 '16 at 00:56
  • 1
    `mvn idea:idea` solved the issue in my case. Thank you. – mmdemirbas Jun 06 '18 at 09:03
5

Generated code, using jaxb2-maven-plugin, was missing for me in Intellij 2017.1 whereas Eclipse Neon created it. Fixed it from context menu of module by selecting 'Maven -> Generate Sources and Update Folders'.

striker77
  • 544
  • 1
  • 6
  • 17
1

Try with maven-jaxb2-plugin. If it does not work then it's IDEA problem.

In Maven you can add new source roots per configuration. Maven plugins can do this programmatically. This is for sure the case with maven-jaxb2-plugin. Then, if IDEA does not recognize it, then it's a problem on that side.

Ryan Nelson
  • 4,466
  • 5
  • 29
  • 45
lexicore
  • 42,748
  • 17
  • 132
  • 221
0

You can use the Maven Build Helper Plugin. It is located at http://www.mojohaus.org/build-helper-maven-plugin/

It allows to configure additional source roots. And the maven integration of IntelliJ will add the new source root. We are using this feature in quite a few builds and it works just fine. Tested with vers. 13 of IntelliJ IDEA.

Ryan Nelson
  • 4,466
  • 5
  • 29
  • 45
Andy Pah
  • 251
  • 2
  • 5