Я получаю исключение ClassNotFound в файле UserServiceApplication.kt.
Ниже приведена структура моего проекта.
Root Project
|
|---settings.gradle
|
|---common (library module) (Spring boot project)
| |
| |--build.gradle
| |--src/main/kotlin/com/simbalarry/common/util/StringValidator.kt
| |--src/main/kotlin/com/simbalarry/common/MainApp.kt
| |
|---user-manager (Spring boot project) (uses common)
| |--build.gradle
| |--src/main/kotlin/somepackage/UserServiceApplication.kt
Содержимое всех файлов RootProject / settings.gradle
include ':common', ':user-manager'
rootProject.name = 'home-cuisine'
common / build.gradle
plugins {
id 'java-library'
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.simbalarry'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
ext['kotlin.version'] = '1.2.71'
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
common / com / simbalarry / common / util / StringValidator.kt
package com.simbalarry.common.util
class StringValidator {
fun hello(): String {
return "Bye"
}
}
common / com / simbalarry / common / MainApp.kt
package com.simbalarry.common
class MainApp
fun main(args: Array<String>) {
}
user-manager / build.gradle
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.simbalarry'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation project(':common')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
user-manager / UserServiceApplication.kt
package com.simbalarry.usermanager
import com.simbalarry.common.util.StringValidator
class UserServiceApplication
fun main(args: Array<String>) {
println("Hieex")
val stringValidator = StringValidator()
}
Когда я запускаю загрузку bootRun для user-managerпакет, я получаю следующее исключение
E:\Repos\HC7\user-manager>gradle bootRun
> Task :user-manager:bootRun FAILED
Hieex
Exception in thread "main" java.lang.NoClassDefFoundError: com/simbalarry/common/util/StringValidator
at com.simbalarry.usermanager.UserServiceApplicationKt.main(UserServiceApplication.kt:9)
Caused by: java.lang.ClassNotFoundException: com.simbalarry.common.util.StringValidator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':user-manager:bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_181\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.2.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 4s
4 actionable tasks: 1 executed, 3 up-to-date
Может кто-нибудь подсказать мне, что не так с этим проектом.У меня была эта проблема в более крупном проекте, но я вставил здесь суженную проблему.