java - 在heroku上部署项目时如何修复maven插件和java版本错误?

标签 java maven spring-boot heroku

我一直在尝试使用 git hub 存储库在 heroku 上部署 Spring Boot 项目,但我不断收到错误:

[错误] 无法在项目慈善机构上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile): 致命编译错误: 无效目标版本: 12 -> [帮助1]

我尝试按照 Heroku 上的建议创建 system.properties:

java.runtime.version=12 maven.version=3.7.0

并将heroku插件添加到pom.xml。

我正在复制下面的 pom.xml 文件:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>pl.coderslab</groupId>
<artifactId>charity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>charity</name>

<properties>
    <java.version>12</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-validation</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.8.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId><artifactId>activation</artifactId>
        <version>1.1.1</version></dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId><artifactId>jaxb-api</artifactId>
        <version>2.3.0</version></dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId>
        <version>2.3.0</version></dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version></dependency>
</dependencies>

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

我错过了什么?

最佳答案

修改您的 system.properties 文件,使其看起来完全像这样:

java.runtime.version=12

然后确保它已提交到 Git 并使用 git ls-files 推送到 Github。

你不需要maven.version,如果你想控制你的maven版本,你应该使用Maven Wrapper .

关于java - 在heroku上部署项目时如何修复maven插件和java版本错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58641148/

相关文章:

java - 无法访问类型 foo 的封闭实例。为什么?

java - 关于如何创建新的 Maven 原型(prototype)的任何好的高级指南?

java - 尝试使用 Maven 在 JOOQ 中实现 EnumConverter 时出错

spring-boot - 如何使用 spring-boot-test 中的 ApplicationContextRunner 测试 @ConfigurationProperties?

java - 无法使用 Jedis Lib 在本地连接到 aws 上的 Elasticache 集群

Java 将多个 HashMap 写入文件

Java - 在实例化时使用反射来防止字段分配?

maven - 在自定义插件中使用 Gradle 依赖项

spring-boot - Spring Boot yaml 嵌套属性映射到配置类 HashMap

java - Thymeleaf 3.0 模板引擎,从两个位置获取模板