使用java 9和maven的spring引导应用程序的编译失败 [英] compilation failure for spring boot application with java 9 and maven
问题描述
我正在尝试使用 java-9
来构建 spring-boot
应用程序,并将其部署到 heroku上
。作为构建工具,我使用 maven
。
我生成了 spring boot 1.5
使用 initializr
的应用程序。我添加了 heroku
特定文件,并添加了 toolchains.xml
至 .m2
maven-compiler-plugin
。
$ b 我的
pom.xml code>看起来像这样 <?xml version =1.0encoding =UTF-8?> ;
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
<包装> jar< / packaging>
<名称> java-cloud-sample< / name>
< description> Spring Boot的演示项目< / description>
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.5.6.RELEASE< / version>
< relativePath /> <! - 从存储库查找父级 - >
< / parent>
<属性>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< project.reporting.outputEncoding> UTF-8< /project.reporting.outputEncoding>
< java.version> 1.9< /java.version>
< maven.compiler.source> 1.9< /maven.compiler.source>
< maven.compiler.target> 1.9< /maven.compiler.target>
< maven.compiler.release> 9< /maven.compiler.release>
< / properties>
<依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-actuator< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-devtools< / artifactId>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> org.postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-test< / artifactId>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
<执行次数>
<执行>
<目标>
< goal> build-info< / goal>
< /目标>
<配置>
< 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>
< /执行>
< /执行次数>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.6.0< / version>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-toolchains-plugin< / artifactId>
< version> 1.1< / version>
<配置>
< toolchains>
< jdk>
< version> 1.9< / version>
< vendor> oracle< / vendor>
< / jdk>
< / toolchains>
< / configuration>
<执行次数>
<执行>
<目标>
< goal> toolchain< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>
< / project>
当我尝试使用 mvn clean package $ c $编译项目c>出现错误
$ p $ [错误]编译错误:
[信息] ------- -------------------------------------------------- ----
[错误] javac:无效标志:-Xmodule:null
用法:javac< options> <源文件>
使用--help列出可能的选项
[信息] 1错误
[信息] ---------------- ---------------------------------------------
[ INFO] ------------------------------------------------ ------------------------
[INFO] BUILD FAILURE
[INFO] ---------- -------------------------------------------------- ------------
[信息]总时间:3.031 s
[信息]完成时间:2017-08-30T21:08:25 + 03:00
[INFO] Final Memory:20M / 309M
[INFO] --------------------------------- ---------------------------------------
[错误]无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.6.0:
项目上的testCompile(default-testCompile)java-cloud-sample:编译失败
[错误] javac:invalid flag: -Xmodule:null
[错误]用法:javac< options> <源文件>
[错误]使用--help列出可能的选项
[错误]
[错误]
[错误] - > [帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整的调试日志记录。
[错误]
[错误]有关错误和可能解决方案的更多信息,请阅读以下文章:
[错误] [帮助1] http://cwiki.apache.org / confluence / display / MAVEN / MojoFailureException
module-info
看起来像这样
module com.lapots.breed.platform.cloud.javacloudsample {
需要spring。开机;
}
有什么问题?项目可在这里
github仓库
<解决方案maven-compiler-plugin 3.6.0基于 module-info.class
的第一个签名,这已经改变了几次。它与当前的Java 9签名不兼容。在使用最新版本的JDK 9时,您应该使用3.6.2。
I am trying to build spring-boot
application that uses java-9
and would be deployed to heroku
. As a build tool I use maven
.
I generated spring boot 1.5
application using initializr
. I added heroku
specific files and added toolchains.xml
to .m2
repository for maven-compiler-plugin
.
My pom.xml
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>
<groupId>com.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>java-cloud-sample</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.9</java.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.release>9</maven.compiler.release>
</properties>
<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-devtools</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<configuration>
<toolchains>
<jdk>
<version>1.9</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I try to compiler project using mvn clean package
I get the error
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] javac: invalid flag: -Xmodule:null
Usage: javac <options> <source files>
use --help for a list of possible options
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.031 s
[INFO] Finished at: 2017-08-30T21:08:25+03:00
[INFO] Final Memory: 20M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile (default-testCompile) on
project java-cloud-sample: Compilation failure
[ERROR] javac: invalid flag: -Xmodule:null
[ERROR] Usage: javac <options> <source files>
[ERROR] use --help for a list of possible options
[ERROR]
[ERROR]
[ERROR] -> [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/MojoFailureException
module-info
looks like this
module com.lapots.breed.platform.cloud.javacloudsample {
requires spring.boot;
}
What is the problem? Project available here
github repository
解决方案 maven-compiler-plugin 3.6.0 is based on the first signature of module-info.class
, which has changed a couple of times. It is not compatible with current Java 9 signature. You should use 3.6.2 when using most recent versions of JDK 9.
这篇关于使用java 9和maven的spring引导应用程序的编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!