'How to add source files generated in target folder as library in Intellij Idea

I'm trying to checkout a maven project from SubVersion. In the pom.xml file it's specified to generate web service proxy classes in the target folder. Here's the concerned part of the pom.xml file:

          <execution>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>

                    <wsdlUrls>                               
                        <wsdlUrl>${basedir}/config/mnpBusinessService.wsdl</wsdlUrl>
                    </wsdlUrls>

                    <packageName>com.mnp.services.business</packageName>
                    <sourceDestDir>${basedir}/target/generated-code/src</sourceDestDir>
                </configuration>
                <id>ws-import-mnpBusinessService</id>
                <phase>generate-sources</phase>
           </execution>

As you can see the maven is instructed to create the generated proxy classes in the ${basedir}/target/generated-code/src directory. When I checkout with NetBeans, a seperate GeneratedCode directory is created as part of the project. And any package inside this directory is available to the main source files. But when I checkout with Intellij Idea,

  1. I have to manually execute install command and second.

  2. The files are indeed created in the specified directory but main source files can't see those packages.

I've tried Project Structure|Modules|MyModule|Dependencies|Add Jars or directories and Project Structure|Libraries|Add|Java|Mydiectoryy. But neither helped. I also tried removing the target folder from Exclude list but that didn't help either. What should I do to be able to import generated proxy classes in Intellij Idea. It's the Ultimate version 2016.2.4.



Solution 1:[1]

I ended up creating a module from existing sources, where existing sources folder is my generated-code folder. Then from the Modules|My main module|Dependencies|Add module and chose the just created module. And voila.

Here are the steps I followed:

1.

enter image description here

2.

enter image description here

3

enter image description here

4

enter image description here

Solution 2:[2]

2022 UPDATE

In my case, I was manually running an ant build script to generate required source files before attempting to compile the main sources. The maven generatedSourcesDirectory seems primarily meant for annotations, but it provides an automated one-line solution to this problem.

Change ${basedir}/target/generated-code/src to ${project.build.directory}/generated-sources/main/java and add this line to the maven-compiler-plugin <configuration> section:

<generatedSourcesDirectory>${project.build.directory}/generated-sources/main/java</generatedSourcesDirectory>

You may need Delegate IDE build/run actions to Maven enabled. It's in Build Tools | Maven | Runner.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 cb4