2017-09-08 2 views
4

J'ai un project. A l'origine, il était un seul projet de module avec la structure comme celui-cierreur irrécupérable compilant indicateur non valide --module-path

java-cloud-sample\ 
    src\ 
     main\ 
      java 
    pom.xml 

j'ai décidé de le faire dans une structure multi-module - J'utilise java 9 de toute façon. Je séparés comme ça

java-cloud-sample\ 
    java-cloud-rest-api\ 
     src\ 
     pom.xml 
    pom.xml 

Où racine pom.xml ressemble à ce

<?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> 

    <groupId>com.lapots.breed.platform.cloud</groupId> 
    <artifactId>java-cloud-sample</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <modules> 
     <module>java-cloud-rest-api</module> 
    </modules> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.6.RELEASE</version> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <maven.compiler.source>1.9</maven.compiler.source> 
     <maven.compiler.target>1.9</maven.compiler.target> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.2</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>3.0.0</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>3.0.1</version> 
       <executions> 
        <execution> 
         <id>copy-dependencies</id> 
         <phase>package</phase> 
         <goals><goal>copy-dependencies</goal></goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 


</project> 

et le module pom.xml ressemble à ce

<?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>com.lapots.breed.platform.cloud</groupId> 
     <artifactId>java-cloud-sample</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <artifactId>java-cloud-rest-api</artifactId> 
    <description>Demo project for Spring Boot</description> 
    <packaging>jar</packaging> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-devtools</artifactId> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
      <scope>runtime</scope> 
     </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> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <goals> 
          <goal>build-info</goal> 
         </goals> 
         <configuration> 
          <additionalProperties> 
           <encoding.source>${project.build.sourceEncoding}</encoding.source> 
           <encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting> 
           <java.source>${maven.compiler.source}</java.source> 
           <java.target>${maven.compiler.target}</java.target> 
          </additionalProperties> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Mais quand je tente d'exécuter mvn clean package je reçois

INFO] java-cloud-rest-api ................................ FAILURE [ 1.060 s] 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.104 s 
[INFO] Finished at: 2017-09-08T17:15:46+03:00 
[INFO] Final Memory: 27M/331M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.2:compile (default-compile) on project java-cloud-rest-api: Fatal error compiling: invalid flag: --module-path -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command 
[ERROR] mvn <goals> -rf :java-cloud-rest-api 

Quel est le problème? (Peut-être que je devrais diviser maven projet en modules séparés et chaque module maven divisé en modules java)

Répondre

6

Cette erreur se produit lorsque installé sur votre ordinateur est configuré avec que la version java par défaut. Vous pouvez confirmer cela en exécutant

mvn -version 

sur votre terminal et la vérification de la version Java indiqué dans la configuration.

Pour résoudre la version à , vous pouvez créer/modifier le mavenrc (sur MacOS) fichier sur votre machine:

vi ~/.mavenrc 

pour inclure ces

export PATH 
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/ 
export PATH=${PATH}:$JAVA_HOME/bin 

Une fois que vous enregistrer cette configuration, vous pouvez confirmer que maven devrait utiliser Java version 9 en utilisant la même commande, puis votre projet doit générer sans l'erreur indiquée.

+1

Oh je vois. J'ai 'java 8' par défaut au travail mais à la maison j'ai' java 9' donc je vérifie là. – lapots

+1

@ user1432980 Donc, Maven configuré avec Java version 9 devrait générer sans cette erreur. Vous pouvez configurer en conséquence. – nullpointer

+1

en effet avec avoir 'java_home' réglé avec' java 9' il compile (avec l'exception 'unnamed module' mais au moins c'est quelque chose) – lapots