Reputation: 769
I have a project where I am using both Kotlin and Java code. My main Kotlin code (including the @SpringBootApplication main class) are in src/main/kotlin, but there is some legacy client library code which is in src/main/java. I also have some tests in src/test/kotlin.
In IntelliJ I can run the tests without issue, but when I run the test using gradle test I get errors Unresolved reference
and cannot access class **
. I am unsure why this is happening. The errors related to code in the Java classes.
My kotlin code and tests are in a slightly different package to the client library code; my main code is in a package called com.sky.vision.playlistapi and the client library is in a package called com.sky.nifty. I wonder if this could be the root of the problem?
My build.gradle file is here:
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')
}
And here is my project layout:
If anyone is able to help me understand the problem I would be grateful.
Upvotes: 2
Views: 3219
Reputation: 769
It turns out the problem was that I had some .java
classes inside src/main/kotlin
package. Once I moved these under src/main/java
package the problem was resolved.
Upvotes: 2