Heroku无法检测到Java 11版本。

5

我正在尝试使用Heroku Maven插件将Java jar部署到Heroku。由于我使用的是Java 11,所以我在根文件夹(pom.xml所在位置)中添加了system.properties并设置了java.runtime.version = 11 。然而它似乎没有起作用!

我的插件:

            <plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <includeTarget>false</includeTarget>
                    <includes>
                        <include>${project.build.directory}/${project.build.finalName}.jar</include>
                    </includes>
                    <processTypes>
                        <web>java $JAVA_OPTS -jar ${project.build.directory}/${project.build.finalName}.jar</web>
                    </processTypes>
                </configuration>
            </plugin>

当我执行 git push heroku master 命令时,它会使用jdk 8开始构建过程。


remote: Building source:
remote: 
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote:        $ mvn -DskipTests clean dependency:list install


最终构建失败,错误为:
 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ImpactHub_bot: Fatal error compiling: invalid flag: --release -> 

如何将 JDK 版本设置为 11?我已经尝试在配置中添加 ${java.version},但没有帮助。
1个回答

3

这就是您指定Java版本的方法,详情请参见:https://devcenter.heroku.com/articles/java-support#specifying-a-java-version

You can specify a Java version by adding a file called system.properties to your application.

Set a property java.runtime.version in the file:

java.runtime.version=11

我在我的项目中也使用了它,并且它可以正常工作。


确保你的system.properties文件保存为All Files。此外,它应该位于Git仓库的根目录下。
它可能有一个.txt扩展名。如果失败了,请向Heroku提出支持工单


1
我已经找到了问题所在——它与git push heroku master命令的解释有关。我有一个功能分支,在那里我进行了所有更改,并试图盲目地执行master。因此,我将其更改为feature,然后它选择了Java 11。 - RangerReturn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接