这是我第一次将 ktor 应用程序部署到 Heroku,我收到了错误 无法访问 jar 文件
下面是我的 build.gradle.kts 文件。
我一直在尝试浏览文档和其他 stackoverflow 页面寻求帮助,但无法弄清楚我错了什么。我能够生成 .jar 文件并在 Heroku 上成功构建。我附上了 Heroku 页面的屏幕截图,其中显示了 dynos 中部署的 jar 文件。但仍然出现上述错误。任何帮助都会很棒。
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.com.intellij.openapi.vfs.StandardFileSystems.jar
val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project
val exposed_version: String by project
val postgres_version: String by project
val hikari_version: String by project
plugins {
kotlin("jvm") version "1.9.22"
id("io.ktor.plugin") version "2.3.8"
kotlin("plugin.serialization") version "1.9.22"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
group = "com.schoolcircle"
version = "0.0.1"
application {
mainClass.set("com.schoolcircle.ApplicationKt")
}
tasks {
withType<Jar> {
manifest {
attributes["Main-Class"] = "com.schoolcircle.ApplicationKt"
}
}
}
//tasks.shadowJar {
// manifest {
// attributes["Main-Class"] = application.mainClass.get()
// }
//}
repositories {
mavenCentral()
maven {
url = uri("https://dl.bintray.com/kotlin/exposed")
}
maven { url = uri("https://kotlin.bintray.com/ktor") }
maven {
url = uri("https://repo.spring.io/release")
}
google()
}
tasks {
create("stage").dependsOn("installDist")
}
tasks.test {
enabled = false
}
gradle.taskGraph.whenReady {
if (this.hasTask("stage")) {
tasks.test {
enabled = false
}
}
}
dependencies {
implementation("io.ktor:ktor-server-auth-jvm")
implementation("io.ktor:ktor-server-core-jvm")
implementation("io.ktor:ktor-server-auth-jwt-jvm")
implementation("io.ktor:ktor-server-sessions-jvm")
implementation("io.ktor:ktor-server-netty-jvm")
implementation("io.ktor:ktor-server-locations:$kotlin_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-jackson:$ktor_version")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
testImplementation ("io.ktor:ktor-server-tests:$ktor_version")
implementation("org.jetbrains.exposed:exposed-core:$exposed_version")
implementation("org.jetbrains.exposed:exposed-dao:$exposed_version")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version")
implementation("org.postgresql:postgresql:$postgres_version")
implementation("com.zaxxer:HikariCP:$hikari_version")
}
我的 Procfile 是
web: java -jar ./build/libs/school-backend-all.jar
检查 .gitignore 文件,如果 build 文件夹添加到那里,则可能会添加到那里,因此 jar 文件首先无法上传到 heroku。