为啥当我尝试将我的 Spring Boot 应用程序推送到 heroku 时它返回“致命错误编译:无效目标版本:11”
Posted
技术标签:
【中文标题】为啥当我尝试将我的 Spring Boot 应用程序推送到 heroku 时它返回“致命错误编译:无效目标版本:11”【英文标题】:Why when i try push my Spring boot app to heroku it return "Fatal error compiling: invalid target release: 11"为什么当我尝试将我的 Spring Boot 应用程序推送到 heroku 时它返回“致命错误编译:无效目标版本:11” 【发布时间】:2020-07-04 02:55:02 【问题描述】:我正在尝试将我的 Spring Boot 应用程序推送到 Heroku,但我在下面收到此错误。
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 41 source files to /tmp/build_4ad2779b666eb1cd25b32f96d104b00b/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.273 s
[INFO] Finished at: 2020-03-23T14:23:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project algamoney-api: Fatal error compiling: invalid target release: 11 -> [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
!错误:无法使用 Maven 构建应用程序 我们很抱歉这个构建失败了!如果您在应用程序代码中找不到问题, 请提交工单以便我们提供帮助:https://help.heroku.com/ !推送被拒绝,无法编译 Java 应用程序。 !推送失败
我检查了 JAVA_HOME、java -version
、java -version
和 mvn -version
都指向同一个 java 版本:11.0.3
我的 POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.5.发布 com.hugo.algamoney-api algamoney-api 1.0.0-快照 algamoney-api 工坊Spring Boot com mongodb
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- Dependencia do hibernate e Jackson para funcionar o datatype -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Pega a causa da exceção -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.8</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
【问题讨论】:
嗨@雨果!您可以查看这个:***.com/questions/53604111/… 看起来与您的问题非常相似。希望对您有所帮助! JAVA_HOME 设置不正确...... 嗨@khmarbaise! JAVA_HOME设置正确,问题不在于 我怀疑导致失败invalid target release: 11
看起来您的 JAVA_HOME 指向的 JDK 版本小于 9...
【参考方案1】:
问题解决了!经过大量尝试和错误后,它可以正常工作,我将在我采取的步骤下方发布:
-
将整个项目更改为 java 11,以便于项目的 JRE 在 1.8 版本中;
创建一个
system.properties
并使用以下配置:java.runtime.version=11.0.3
;
再次提交并添加推送到heroku;
【讨论】:
除非你真的特别需要11.0.3
,否则我建议你使用java.runtime.version=11
。这可确保您在每次部署时获得最新的 Java 11 版本。
`!错误:不支持的 Java 版本:11.0.3 请检查您的 system.properties 文件以确保 java.runtime.version 在开发中心支持的版本列表中:devcenter.heroku.com/articles/… 您也可以从您的 repo 中删除 system.properties安装默认的 1.8 版本。如果您仍然遇到问题,您可以在这里打开支持票:help.heroku.comThanks, Heroku`【参考方案2】:
在 pom.xml 中
<java.version>1.8</java.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
也有一次
$ mvn clean install
【讨论】:
以上是关于为啥当我尝试将我的 Spring Boot 应用程序推送到 heroku 时它返回“致命错误编译:无效目标版本:11”的主要内容,如果未能解决你的问题,请参考以下文章
当我将 Spring Boot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 Spring Boot 连接到 RDS 时出现 502 错误网关
无法将我的spring-boot应用程序与mongodb云图集连接起来
为啥在启动 Spring Boot 应用程序时出现 Gson builder 错误?