Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[m2e-users] Multi-release jar project: howto automatically add additional source folder?

Hi,

I'm working on some projects that actually target Java 8, but are already prepared to be used in modular applications, i.e. Java 11. I'm following the multirelease/single project runtime pattern shown here:
https://github.com/apache/maven-compiler-plugin/blob/master/src/it/multirelease-patterns/singleproject-runtime/pom.xml


I have the following snippet in my parent pom:

<profile>
        <id>jdk9+</id>
        <activation>
                <jdk>[9,)</jdk>
        </activation>
        <build>
                <pluginManagement>
                        <plugins>
                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-compiler-plugin</artifactId>
                                        <version>3.8.1</version>
                                        <configuration>
                                                <release>8</release>
                                        </configuration>
                                </plugin>
                        </plugins>
                </pluginManagement>
        </build>
</profile>

<profile>
        <id>jdk11</id>
        <activation>
                <jdk>[11,)</jdk>
                <file>
                        <exists>${basedir}/src/main/java11</exists>
                </file>
        </activation>
        <build>
                <pluginManagement>
                        <plugins>
                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-compiler-plugin</artifactId>
                                        <version>3.8.1</version>
                                        <executions>
                                                <execution>
                                                        <id>jdk11</id>
                                                        <goals>
                                                                <goal>compile</goal>
                                                        </goals>
                                                        <configuration>
                                                                <release>11</release>
                                                                <compileSourceRoots>
                                                                        <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
                                                                </compileSourceRoots>
                                                                <multiReleaseOutput>true</multiReleaseOutput>
                                                        </configuration>
                                                </execution>
                                        </executions>
                                </plugin>

                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-jar-plugin</artifactId>
                                        <version>3.2.0</version>
                                        <executions>
                                                <execution>
                                                        <id>default-jar</id>
                                                        <configuration>
                                                                <archive>
                                                                        <manifestEntries>
                                                                                <Multi-Release>true</Multi-Release>
                                                                        </manifestEntries>
                                                                </archive>
                                                        </configuration>
                                                </execution>
                                        </executions>
                                </plugin>
                        </plugins>
                </pluginManagement>
        </build>
</profile>


Given the following structure in a depending project:

src/main/java
src/main/resources
src/main/java11

...

I'm able to compile it both with Java 8 or Java 11 as default JVM. So far, so good.

Question:
With Java 11 as default I have to manually add src/main/java11 as an additional source folder in Eclipse because it isn't discovered automatically when I import such a project.
Is there a way to let m2e do this automatically for me?


Regards

Thorsten

Back to the top