dks*_*551 5 gradle kotlin spring-boot spring-boot-gradle-plugin
我试图复制Spring Boot Kotlin示例项目https://github.com/JetBrains/kotlin-examples/tree/master/tutorials/spring-boot-restful。我添加了更多依赖项,当我尝试构建可执行 jar 并运行它时,出现错误:
无法找到或加载主类...
Gradle 构建脚本:
buildscript {
ext.kotlin_version = '1.1.3' // Required for Kotlin integration
ext.spring_boot_version = '1.5.4.RELEASE'
repositories {
jcenter()
}
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"
}
}
/*plugins {
id 'org.springframework.boot' version '2.0.0.RELEASE'
}*/
apply plugin: 'kotlin' // Required for Kotlin integration
apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'org.jetbrains.kotlin.demo.Applicationkt'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration
compile("org.springframework.boot:spring-boot-starter-web")
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'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)
更改Applicationkt为ApplicationKt将工作,顺便说一句,您可以将 Kotlin 版本升级到1.3.50.
通过Applicationkt我的意思是一个在这条线:
attributes 'Main-Class': 'org.jetbrains.kotlin.demo.Applicationkt'
Run Code Online (Sandbox Code Playgroud)
小智 5
Kotlin 将应用程序文件编译为两个不同的文件:
第二个文件是main函数所在的位置,因此您必须在 build.gradle 文件中使用该名称。
mainClassName = 'org.jetbrains.kotlin.demo.Application Kt '
| 归档时间: |
|
| 查看次数: |
11025 次 |
| 最近记录: |