1

I am starting a new maven project that should run with Spring Boot (in case that's relevant), and it compiled fine. But then, I decided to start using Java9-modules. So, I had eclipse generate the module-info.java file that looks like this:

module BirdTreeModel {
    exports mjl.familytree.birdtree;

    requires junit;
    requires spring.boot;
    requires spring.boot.autoconfigure;
    requires spring.boot.test;
    requires spring.test;
}

This causes a compile error, however. Eclipse says: "Syntax error on token "module", interface expected". (And when I do a Maven clean install, it says "Compilation failure: ...module not found: junit" and same for modules spring.boot.test and spring.test).

echo %JAVA_HOME% gives C:\Program Files\Java\jdk-12

mvn -version gives:

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:1
4+02:00)
Maven home: `D:\Programming practice\maven\apache-maven-3.5.4\bin\..`
Java version: 12, vendor: Oracle Corporation, runtime: `C:\Program Files\Java\jdk-12`
Default locale: `en_US`, platform encoding: `Cp1252`.
OS name: "Windows 7", version: "6.1", arch: "AMD64", family: "Windows"

The run configurations of the Maven build of the project are also on JDK-12

My pom looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>mjl.familytree</groupId>
    <artifactId>birdtree-model-dao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>birdtree-model-dao</name>
    <description>My family tree program</description>

    <repositories>
        <repository>
            <id>repository.spring.release</id>
            <name>Spring GA Repository</name>
            <url>http://repo.spring.io/release</url>
        </repository>
    </repositories>

    <properties>
        <maven.compiler.source>1.12</maven.compiler.source>
        <maven.compiler.target>1.12</maven.compiler.target>
        <maven.compiler.release>12</maven.compiler.release>
        <java.version>12</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
Sae1962
  • 1,122
  • 15
  • 31
MJL
  • 352
  • 3
  • 11
  • Does replacing `1.12` with `12` (two matches) in your `pom.xml` fix your issue? – howlger Apr 22 '19 at 18:11
  • I'm afraid not. – MJL Apr 22 '19 at 20:09
  • The syntax error is probably because of the wrong _compiler compliance level_ in _Project > Properties: Java Compiler_. The Maven failure might caused in `pom.xml` by a missing repository or by missing dependencies versions (`...`). – howlger Apr 23 '19 at 06:08
  • You're right, the compiler compliance level was set to 1.5. So I changed it to 12. (I had to install Java 12 support from the Eclipse Marketplace, in order for the dropdown to give me that option.) The line with the module now no longer gives that syntax error. However... – MJL Apr 23 '19 at 15:13
  • there's still the problem " cannot be resolved to a module" for each "require". For junit, I solved this by adding 4.12 into the pom. I now get a warning "Duplicating managed version" and "name is unstable", but no more error. For the others, I added the jars from my maven repo into the module path. But is that how it's supposed to work, if you have a maven project with Java9-modules? You include every dependency twice, once as a maven dependency, once as a module dependency? Also, I can't find a corresponding jar for spring.test. Why did Eclipse add this? – MJL Apr 23 '19 at 15:13

0 Answers0