spring-boot - 将 Spring Boot 应用程序推送到 Heroku 时出错

标签 spring-boot maven heroku compiler-errors

我正在尝试在 Heroku 上推送我的 Spring Boot 应用程序,我收到一个错误:无法使用 Maven 构建应用程序,即无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile(默认-compile) 项目 BlogApplication: fatal error 编译:无效的目标版本:11。
日志:

 8.8 MB/s)
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar (27 kB at 694 kB/s)
remote:        [INFO] Changes detected - recompiling the module!
remote:        [INFO] Compiling 26 source files to /tmp/build_bde72765/target/classes
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time:  14.367 s
remote:        [INFO] Finished at: 2020-12-26T03:02:12Z
remote:        [INFO] ------------------------------------------------------------------------
remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project BlogApplication: Fatal error compiling: invalid target release: 11 -> [Help 1]
remote:        [ERROR] 
remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote:        [ERROR] 
remote:        [ERROR] For more information about the errors and possible solutions, please read the following articles:
remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
remote: 
remote:  !     ERROR: Failed to build app with Maven
remote:        We're sorry this build is failing! If you can't find the issue in application code,
remote:        please submit a ticket so we can help: https://help.heroku.com/
remote: 
remote:  !     Push rejected, failed to compile Java app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: a12b93ea38df794a63db75682e8389ef779ed088
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version a12b93ea38df794a63db75682e8389ef779ed088
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to blog-application-mvc.
remote: 
To https://git.heroku.com/blog-application-mvc.git
 ! [remote rejected] master -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/blog-application-mvc.git'

pom.xml
<?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 https://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.4.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.blog</groupId>
    <artifactId>BlogApplication</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>BlogApplication</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <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-thymeleaf</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>
        </dependency>-->

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

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

最佳答案

Heroku 提供了一个 Java 8 运行时,您可以根据需要对其进行更改。
创建文件system.properties在您的项目的根目录中,其中包含:

java.runtime.version=11

关于spring-boot - 将 Spring Boot 应用程序推送到 Heroku 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65453406/

相关文章:

java - 当我有 2 个具有相同端点字符串值的 Controller 方法时,为什么会收到 "requestMappingHandlerMapping"错误

spring - Spring PermissionEvaluator 中的@Autowired

java - Tomcat context.xml 和 context.properties 文件

java - Maven Jar 中的静态 Web 资源?

heroku - symfony5 - heroku - 找不到网址 404

database - 如果我超过了 Heroku 上的数据库大小限额,会发生什么情况?

Heroku buildpack - 安装 texlive 二进制包

java - 部署到WebLogic时获取 "weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addAll"

spring - 在 flyway 迁移脚本之前执行 JPA 表创建

maven - JUnit + Maven +并行测试执行错误