Unable to use Intellij with a generated sources folder

后端 未结 11 1855
孤城傲影
孤城傲影 2020-12-01 01:00

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 cust

相关标签:
11条回答
  • 2020-12-01 01:39

    Solved it by removing the "Excluded" in the module setting (right click on project, "Open module settings").

    0 讨论(0)
  • 2020-12-01 01:43

    The fix

    Go to Project Structure - Modules - Source Folders and find the target/generated-sources/antlr4/com/mycompany - click Edit properties and set Package prefix to com.mycompany.

    This is exactly the reason why we can set Package prefix on source dirs.


    Different but related problem here

    0 讨论(0)
  • 2020-12-01 01:46

    Whoever wrote that plugin screwed up big time. That's not the way to do it!

    Any workaround would be a huge hack, make the plugin developer aware of his bug.

    Sorry, that's the only thing to do.


    OK here's a hack, directly after your plugin's execution, use the antrun plugin to move the directory somewhere else:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <configuration>
              <target>
                <move todir="${project.build.directory}/generated-sources/toolname/com"
                      overwrite="true">
                    <fileset dir="${project.build.directory}/generated-sources/com"/>
                </move>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
    

    In this example, toolname should be replaced by anything that uniquely identifies the plugin that created the code and com stands for the root of the created packages. If you have multiple package roots, you probably need multiple <move> tasks.

    But if the plugin adds the folder as source folder, then you're screwed.

    0 讨论(0)
  • 2020-12-01 01:47

    I'm using Maven (SpringBoot application) solution is:

    1. Right click project folder
    2. Select Maven
    3. Select Generate Sources And Update Folders

    Then, Intellij automatically import generated sources to project.

    0 讨论(0)
  • 2020-12-01 01:49

    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>
    
    0 讨论(0)
提交回复
热议问题