define additional source directory in maven

*爱你&永不变心* 提交于 2019-11-30 01:15:09

问题


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?


回答1:


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.




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/10735380/define-additional-source-directory-in-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!