Spring Boot 如何修复Heroku部署构建的错误

nwlqm0z1  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(211)

当我尝试在heroku上部署一个应用程序时,我遇到了这个问题。我搜索了一下,看到有些人因为pom.xml而遇到了这个问题,我采取了指示的步骤,但仍然无法构建它。
构建问题如下

  1. Changes detected - recompiling the module! :dependency
  2. remote: [INFO] Compiling 37 source files with javac [debug release 11] to target/classes
  3. remote: [INFO] ------------------------------------------------------------------------
  4. remote: [INFO] BUILD FAILURE
  5. remote: [INFO] ------------------------------------------------------------------------
  6. remote: [INFO] Total time: 8.046 s
  7. remote: [INFO] Finished at: 2023-12-20T04:56:32Z
  8. remote: [INFO] ------------------------------------------------------------------------
  9. remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project RosaAPI2: Fatal error compiling: invalid flag: --release -> [Help 1]
  10. remote: [ERROR]
  11. remote: [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  12. remote: [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  13. remote: [ERROR]
  14. remote: [ERROR] For more information about the errors and possible solutions, please read the following articles
  15. remote: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  16. remote:
  17. remote: ! ERROR: Failed to build app with Maven
  18. remote: We're sorry this build is failing! If you can't find the issue in application code,
  19. remote: please submit a ticket so we can help: https://help.heroku.com/
  20. remote:
  21. remote: ! Push rejected, failed to compile Java app.

字符串
我的pom.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>3.2.0</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>RosaAPI2</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>RosaAPI2</name>
  15. <description>RosaAPI2</description>
  16. <properties>
  17. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18. <java.version>11</java.version>
  19. <maven.compiler.source>1.8</maven.compiler.source>
  20. <maven.compiler.target>1.8</maven.compiler.target>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-web</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-devtools</artifactId>
  30. <scope>runtime</scope>
  31. <optional>true</optional>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.postgresql</groupId>
  35. <artifactId>postgresql</artifactId>
  36. <scope>runtime</scope>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.projectlombok</groupId>
  40. <artifactId>lombok</artifactId>
  41. <version>1.16.22</version>
  42. <optional>true</optional>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework.boot</groupId>
  46. <artifactId>spring-boot-starter-test</artifactId>
  47. <scope>test</scope>
  48. </dependency>
  49. <dependency>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-configuration-processor</artifactId>
  52. <optional>true</optional>
  53. </dependency>
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-starter-security</artifactId>
  57. </dependency>
  58. <dependency>
  59. <groupId>org.springframework.boot</groupId>
  60. <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
  61. </dependency>
  62. <dependency>
  63. <groupId>org.springframework.boot</groupId>
  64. <artifactId>spring-boot-starter-actuator</artifactId>
  65. </dependency>
  66. <dependency>
  67. <groupId>org.springframework.boot</groupId>
  68. <artifactId>spring-boot-starter-aop</artifactId>
  69. </dependency>
  70. <dependency>
  71. <groupId>io.github.resilience4j</groupId>
  72. <artifactId>resilience4j-spring-boot3</artifactId>
  73. <version>2.1.0</version>
  74. </dependency>
  75. <dependency>
  76. <groupId>io.quickchart</groupId>
  77. <artifactId>QuickChart</artifactId>
  78. <version>1.2.0</version>
  79. </dependency>
  80. <dependency>
  81. <groupId>com.google.api-client</groupId>
  82. <artifactId>google-api-client</artifactId>
  83. <version>2.2.0</version>
  84. </dependency>
  85. <dependency>
  86. <groupId>com.google.oauth-client</groupId>
  87. <artifactId>google-oauth-client-jetty</artifactId>
  88. <version>1.34.1</version>
  89. </dependency>
  90. <dependency>
  91. <groupId>com.google.apis</groupId>
  92. <artifactId>google-api-services-calendar</artifactId>
  93. <version>v3-rev20231123-2.0.0</version>
  94. </dependency>
  95. <dependency>
  96. <groupId>com.google.auth</groupId>
  97. <artifactId>google-auth-library-oauth2-http</artifactId>
  98. <version>1.19.0</version>
  99. </dependency>
  100. </dependencies>
  101. <build>
  102. <plugins>
  103. <plugin>
  104. <groupId>org.springframework.boot</groupId>
  105. <artifactId>spring-boot-maven-plugin</artifactId>
  106. <configuration>
  107. <excludes>
  108. <exclude>
  109. <groupId>org.projectlombok</groupId>
  110. <artifactId>lombok</artifactId>
  111. </exclude>
  112. </excludes>
  113. </configuration>
  114. </plugin>
  115. <plugin>
  116. <groupId>org.apache.maven.plugins</groupId>
  117. <artifactId>maven-dependency-plugin</artifactId>
  118. <version>3.0.1</version>
  119. <executions>
  120. <execution>
  121. <id>copy-dependencies</id>
  122. <phase>package</phase>
  123. <goals><goal>copy-dependencies</goal></goals>
  124. </execution>
  125. </executions>
  126. </plugin>
  127. </plugins>
  128. </build>
  129. </project>


我已经将java.runtime.version=11添加到application.properties,我注意到有一个警告说“无法解析配置属性”java.runtime.version“
如果有问题,请使用我的Java版本:

  1. openjdk 17.0.7 2023-04-18 LTS
  2. OpenJDK Runtime Environment Zulu17.42+19-CA (build 17.0.7+7-LTS)
  3. OpenJDK 64-Bit Server VM Zulu17.42+19-CA (build 17.0.7+7-LTS, mixed mode, sharing)

2uluyalo

2uluyalo1#

java.runtime.version=17不应该添加到 application.properties 中,但您需要将其添加到应用程序目录中创建的 system.properties 中。
此外,您可能还需要创建Procfile,其中包含
web:java -Dserver.port=$PORT -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar target/app-0.0.1-SNAPSHOT.jar

相关问题