Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Intellij with a generated sources folder

Related question How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?

I have a custom plugin that generates sources under target/generated-sources (Note no toolname here). So I get sources like target/generated-sources/com/mycompany...etc.

This format cannot be changed at all, so will I be able to configure Intellij into adding it as a source folder. As of now, I can see that Intellij has added target/generated-sources/com as the source folder.

Please note that I do not have the option of configuring the plugin !

UPDATE 1: I do not agree with the fact that I MUST put my generated sources under a tool name folder. It may be a good convention, but if I have only one generator there is no need for me to put it there? Again, in my pom.xml I have a resources section which clearly indicates that target/generated-sources should be treated as a source folder. This works perfectly fine in Eclipse so I have no idea why Intellij would not respect my settings.

TL;DR -> When I put target/generated-sources in the resource section of pom.xml why is Intellij overzealous to add target/generated-sources/com to the classpath?

like image 775
Kannan Ekanath Avatar asked Mar 02 '11 16:03

Kannan Ekanath


People also ask

How do I change the source folder in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules. Select the necessary module and open the Sources tab. next to Source Folders or Test Source Folders. Specify the package prefix and click OK.

What is generated sources in Java?

It's a step in the build process that generates source files from other files, e.g. generating Java source files from XML schema files (JAXB). – Andreas. Nov 13, 2020 at 22:37. Generate Java Code from XSD, JSON, or for example MapStruct etc.

What is Maven generate sources?

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.


1 Answers

You can just change the project structure to add that folder as a "source" directory.

Project Structure → Modules → Click the generated-sources folder and make it a sources folder.

Or:

<plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>build-helper-maven-plugin</artifactId>     <version>1.4</version>     <executions>         <execution>             <id>test</id>             <phase>generate-sources</phase>             <goals>                 <goal>add-source</goal>             </goals>             <configuration>                 <sources>                     <source>${basedir}/target/generated-sources</source>                 </sources>             </configuration>         </execution>     </executions> </plugin> 
like image 195
DaShaun Avatar answered Oct 13 '22 08:10

DaShaun