首页 > 解决方案 > java错误:在heroku上部署时构建失败

问题描述

  1. 当我运行以下命令时:

    git push heroku master
    
  2. 我收到以下错误:

    remote: [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar (21 kB at 1.1 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 404 kB/s)
    remote: [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 4.0 MB/s)
    remote: [INFO] Changes detected - recompiling the module!
    remote: [INFO] Compiling 4 source files to /tmp/build_ca81690e12aa9ecc064d62f3524c8370/target/classes 
    remote: [INFO] ------------------------------------------------------------------------
    remote: [INFO] BUILD FAILURE
    remote: [INFO] ------------------------------------------------------------------------
    remote: [INFO] Total time: 11.868 s
    remote: [INFO] Finished at: 2020-06-03T12:05:45Z
    remote: [INFO] ------------------------------------------------------------------------
    remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project coronavirus-tracker: Fatal error compiling: invalid target release: 12 -> [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: Verifying deploy...
    remote: 
    remote: ! Push rejected to covid2020global. 
    remote: To https://git.heroku.com/covid2020global.git
    

更新:

Maven 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.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.javabrains</groupId>
    <artifactId>coronavirus-tracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>coronavirus-tracker</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>12</java.version>
    </properties>

    <dependencies>
        <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.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>1.8</version>
        </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>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <appName>coronavirus-tracker-master</appName>
                </configuration>
            </plugin-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

标签: javamavenheroku

解决方案


我终于解决了删除 Java 8 的 JRE 路径的问题。之后,maven 终于找到了 JDK 13 的路径。我用这个命令 mvn -v 进行了检查。在这些操作之后,我成功地将我的项目部署到 Heroku!


推荐阅读