【问题标题】:SpringBoot Heroku org.maven.plugins:maven-compiler-plugin:3.8.1:compile failedSpringBoot Heroku org.maven.plugins:maven-compiler-plugin:3.8.1:compile failed
【发布时间】:2021-02-21 21:31:46
【问题描述】:

好吧,我已经看过其他帖子,但无法解决我的问题。 我试图将springboot项目部署到heroku,但出现此错误。 无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile):致命错误编译:无效目标版本:11 -> [帮助 1]

我已经按照 Heroku 指南:

$ git init
$ heroku git:remote -a <project>
$ git add .
$ git commit -am "first"
$ git push heroku master

错误:

remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time:  12.632 s
remote:        [INFO] Finished at: 2020-11-09T22:59:42Z
remote:        [INFO] ------------------------------------------------------------------------
remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project scoringsalud-backend: Fatal error compiling: invalid target releas
e: 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: d8ea942613535eca3b2881713d82bcbea9f267aa
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version d8ea942613535eca3b2881713d82bcbea9f267aa
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 scoringsalud.
remote:
To https://git.heroku.com/scoringsalud.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/scori

ngsalud.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.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>scoringsalud-backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>scoringsalud-backend</name>
    <description>Backend Springboot and MongoDb project for Scoring Salud</description>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</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.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <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>
    </dependencies>

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

</project>

可能是什么问题?如何解决?请问我需要帮助:(

【问题讨论】:

  • 您的错误消息已经告诉您问题所在:Fatal error compiling: invalid target release: 11,即为不兼容的 Java 版本构建。 This questions 处理同样的问题,应该有所帮助。下次,尝试用谷歌搜索应用程序产生的具体错误消息,您将能够更快地找到修复程序。
  • 是的,我已经这样做了,正如我所说,我已经搜索并阅读了其他帖子,但无法解决我的问题,这就是我在按照他们在那篇帖子中所说的操作后看到的错误
  • 在您的pom.xml 中,您设置属性&lt;java.version&gt;11&lt;/java.version&gt;。您确定您的源环境(编译发生的地方,即 Heroku)和目标环境(应用程序实际运行的地方)都安装了 Java 11 并且 JAVA_HOME 指向正确的目录?
  • 您是否尝试过在项目的根目录下创建system.properties 文件:java.runtime.version=11 devcenter.heroku.com/changelog-items/1489

标签: java spring spring-boot maven heroku


【解决方案1】:

我可以通过将所有内容(包括我的路径)降级到 1.8 版来解决这个问题

【讨论】:

    【解决方案2】:

    改变

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

    <java.runtime.version>11</java.runtime.version>
    

    【讨论】:

    • 这解决了我的问题。谢谢
    猜你喜欢
    • 2020-05-10
    • 2020-06-24
    • 2021-03-11
    • 2021-10-19
    • 2022-11-17
    • 1970-01-01
    • 2020-07-29
    • 2020-09-02
    • 2020-11-20
    相关资源
    最近更新 更多