【发布时间】:2018-06-20 18:17:34
【问题描述】:
我有一个项目同时使用 Kotlin 和 Java 代码。我的主要 Kotlin 代码(包括 @SpringBootApplication 主类)在 src/main/kotlin 中,但是在 src/main/java 中有一些遗留的客户端库代码。我在 src/test/kotlin 也有一些测试。
在 IntelliJ 中,我可以毫无问题地运行测试,但是当我使用 gradle test 运行测试时,我收到错误 Unresolved reference 和 cannot access class **。我不确定为什么会这样。与 Java 类中的代码相关的错误。
我的 kotlin 代码和测试与客户端库代码的包略有不同;我的主要代码位于名为 com.sky.vision.playlistapi 的包中,客户端库位于名为 com.sky.nifty 的包中。我想知道这是否是问题的根源?
我的 build.gradle 文件在这里:
buildscript {
ext {
kotlinVersion = '1.2.10'
}
}
plugins {
id 'java'
id 'org.springframework.boot' version '1.5.9.RELEASE'
id 'org.jetbrains.kotlin.jvm' version'1.2.10'
id 'org.jetbrains.kotlin.plugin.allopen' version '1.2.10'
id 'org.jetbrains.kotlin.plugin.spring' version '1.2.10'
id 'org.jetbrains.kotlin.plugin.jpa' version '1.2.10'
id 'org.jetbrains.kotlin.plugin.noarg' version '1.2.10'
}
group = 'com.sky.vision'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-security')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa')
compile(group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlinVersion)
compile(group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion)
compile(group: 'org.apache.commons', name: 'commons-lang3', version: '3.4')
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-core')
compile(group: 'com.fasterxml.jackson.core', name: 'jackson-databind')
compile(group: 'org.reflections', name: 'reflections', version: '0.9.9')
compile(group: 'org.aspectj', name: 'aspectjweaver')
compile(group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7')
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test')
testCompile(group: 'org.jetbrains.kotlin', name: 'kotlin-test')
testCompile(group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit')
runtime(group: 'org.postgresql', name: 'postgresql', version: '9.4-1201-jdbc41')
}
这是我的项目布局:
如果有人能帮助我理解这个问题,我将不胜感激。
【问题讨论】:
标签: java spring-boot intellij-idea gradle kotlin