Thank you all for your suggestions. I managed to get the project to build with following maven setup:

```
  <!--
When using compiler from java 8 and older, ignore module files altogether.
        Otherwise, use 2 phase compilation to build
          - all classes for target version and
          - module-info.java with 9+ source and target level
     -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
        <executions>
          <execution>
            <id>default-compile</id>
            <configuration>
              <excludes>
                <exclude>**/module-info.java</exclude>
              </excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>jigsaw</id>
      <activation>
        <jdk>[1.9,)</jdk>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
              <source>1.9</source>
              <target>1.9</target>
            </configuration>
            <executions>
              <execution>
                <id>module-infos</id>
                <phase>compile</phase>
                <goals>
                  <goal>compile</goal>
                </goals>
                <configuration>
                  <includes>
                    <include>**/module-info.java</include>
                  </includes>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
```

It does compile with older javac versions as a bonus. Given this is nothing else than using `-source 9 -target 9` for module-info.java if present, I dare to say maven-compiler-plugin can be adapted to figure this out on its own.

--
oliver

Reply via email to