You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Spring Boot+Gradle(Kotlin)应用时Jar包未找到问题求助

Fixing "Jar Not Found" When Deploying Spring Boot + Kotlin + Gradle App to Heroku

Hey there, let's work through this Jar not found issue you're hitting with Heroku. I've dealt with similar hiccups before, so here's a step-by-step breakdown of what to check and fix:

1. Verify Your Gradle Configuration Generates an Executable Jar

First, make sure your project is set up to build a runnable Spring Boot Jar. For Kotlin DSL (build.gradle.kts), confirm you have the required plugins enabled:

plugins {
    id("org.springframework.boot") version "3.2.0" // Use your compatible version
    id("io.spring.dependency-management") version "1.1.4"
    kotlin("jvm") version "1.9.20"
    kotlin("plugin.spring") version "1.9.20"
}

Run ./gradlew bootJar locally and check the build/libs directory—you should see a file like your-app-name-0.0.1-SNAPSHOT.jar. If this file doesn't exist, your Gradle config is missing something critical for Spring Boot packaging.

2. Add a Procfile to Tell Heroku Where the Jar Is

Heroku needs explicit instructions to run your app. Create a Procfile in your project root (no file extension) with this line:

web: java -jar build/libs/*.jar

Using the wildcard (*.jar) avoids hardcoding your app's version number. If you prefer a fixed name, you can configure the bootJar task to output a consistent filename:

bootJar {
    archiveFileName.set("app.jar")
}

Then update the Procfile to web: java -jar build/libs/app.jar.

3. Check Git Commits Are Complete

Your git push output only shows 2 objects being pushed—this seems suspicious. Make sure you've committed all necessary files:

  • build.gradle.kts and settings.gradle.kts
  • src/ directory with all your Kotlin code
  • gradle/wrapper/ files (to lock your Gradle version for Heroku)
    Avoid ignoring any core config files in .gitignore—Heroku needs these to build your app from scratch.

4. View Full Heroku Logs for Details

Your initial log was truncated, so run this command to get the full build and runtime logs:

heroku logs --tail

Look for lines like "Could not find build/libs/..." or errors during the Gradle build phase. This will tell you if the Jar wasn't generated at all, or if Heroku is looking in the wrong path.

5. Lock Your Gradle Version

To avoid version mismatches between your local environment and Heroku, ensure you're using the Gradle wrapper. If you don't have it already, run ./gradlew wrapper --gradle-version 8.5 (use your preferred version) and commit the gradle/wrapper/ directory to Git. Heroku will use this exact version to build your app.


内容的提问来源于stack exchange,提问作者Luís Soares

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:41:08