Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 609
bert Avatar asked May 24 '12 10:05

bert


People also ask

How to add multiple source directories in a Maven Java project?

By default, Maven uses the /project-path/src/main/java directory as the only source directory. However, in some cases, we need to define additional source directories. In this quick tutorial, we're going to look at how we can add multiple source directories in a Maven-based Java project. 2. Add Source Directory with Build Helper Maven Plugin

What is the default source and resources directory in Maven?

Updated on 2 February, 2019in Apache Maven Views:4,523 Usually when you create any new Maven project, the src/main/java, src/test/java, src/main/resources, src/test/resources directories will be the default source and resources directory of the project.

How do I use add-sources in Maven?

One of its goals is the add-sources, which is intended to add more src directories to the project during the generate-sources phase. We can use it in our project by adding it to our pom.xml: The latest version of the plugin can be found in Maven Central.

What does the Maven plugin do with the source code?

It seems that the compiler maven plugin compiles any java source code located inside this folder whatever the directory that contains them. For example having some (generated or no) source code in target/a, target/generated-source/foo will be compiled and added in the outputDirectory : target/classes.


2 Answers

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.

like image 114
CrazyCoder Avatar answered Oct 02 '22 01:10

CrazyCoder


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>
like image 45
Attila Avatar answered Oct 01 '22 23:10

Attila