Why doesn't Eclipse m2e automatically add generated source folder to classpath?

414 Views Asked by At

I'm using 2018-12 with Java 8, but I'm running Eclipse itself with Java 11.

I have version "1.10.0.20181127-2120" of the m2e plugin.

I have a bunch of projects with similar characteristics. Maven projects run with Spring Boot. They are all stored in git.

For some reason, one of those projects was somewhat brain-damaged this morning. It still would build fine from the command line. Eclipse still knew it was a maven project, but it had no source folders. The .classpath file wasn't empty, it was just very minimal.

I got this particular problem resolved by simply copying the .classpath file from a similar project into this project. That fixed most of the problems, but I remembered that this one project uses a code generator plugin along with the "build-helper-maven-plugin" to indicate where the source is being generated. I found that Eclipse didn't have the generated sources folder as a source folder. I thought adding the "build-helper-maven-plugin" reference was what I needed to do to make Eclipse M2E to automatically detect this, but it doesn't appear to be working.

Once I manually added the generated sources folder as a source folder, that cleaned out the last compile errors.

This is a hopefully relevant excerpt from my pom:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/java-gen</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jsonschema2pojo</groupId>
            <artifactId>jsonschema2pojo-maven-plugin</artifactId>
            <version>0.4.34</version>
            <configuration>
                <sourcePaths>
                    <sourcePath>${basedir}/src/main/schema/...</sourcePath>
                    <sourcePath>${basedir}/src/main/schema/...</sourcePath>
                </sourcePaths>
                <targetPackage>...</targetPackage>
                <annotationStyle>jackson2</annotationStyle>
                <useCommonsLang3>true</useCommonsLang3>
                <useDoubleNumbers>true</useDoubleNumbers>
                <includeAccessors>true</includeAccessors>
                <includeAdditionalProperties>true</includeAdditionalProperties>
                <sourceType>jsonschema</sourceType>
                <generateBuilders>true</generateBuilders>
                <includeJsr303Annotations>true</includeJsr303Annotations>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Update:

Deleting the Eclipse project and reimporting from git made no difference. Same result.

0

There are 0 best solutions below