我有一个以 Kotlin 作为语言,Gradle 作为构建系统支持的 Spring Boot 应用程序。所以基本上我试图从应用程序源和依赖项中构建一个胖 jar,它可以使用 Java 命令行工具运行。
Gradle 构建脚本:
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: "kotlin-spring"
apply plugin: 'org.springframework.boot'
group 'myapp'
version '1.0'
buildscript {
ext.kotlin_version = '1.2.21' // Required for Kotlin integration
ext.spring_boot_version = '1.5.4.RELEASE'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
jar {
zip64 true
manifest {
attributes 'Main-Class': 'app.main.ApplicationKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile("org.jetbrains.kotlin:kotlin-reflect")
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
compile 'org.springframework.boot:spring-boot-starter-web'
compile group: 'org.apache.camel', name: 'camel-spring-boot-starter', version: '2.20.2'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.0.0.RELEASE'
compile group: 'org.apache.camel', name: 'camel-quartz2', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-http4', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-docker', version: '2.20.2'
compile group: 'org.apache.camel', name: 'camel-aws', version: '2.20.2'
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
compile group: 'net.gpedro.integrations.slack', name: 'slack-webhook', version: '1.4.0'
compile group: 'org.json', name: 'json', version: '20180130'
compile group: 'org.jfree', name: 'jfreechart', version: '1.5.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
如果我使用 gradle 命令运行项目,那么它运行良好。但是当我构建 jar 并尝试运行时,它会抱怨以下错误:-
Error: Could not find or load main class app.main.ApplicationKt
应用程序.kt:-
@SpringBootApplication
@ImportResource("classpath*:camel-context.xml")
@ComponentScan("app")
class Application
fun main(args:Array<String>){
SpringApplication.run(Application::class.java, *args)
}
不知道我到底在哪里做错了什么。