https://kotlinlang.org logo
Title
p

Praveen Talari

07/19/2020, 2:36 PM
Issue: Gradle application plugin using Kotlin is not compiling Java files. Steps: 1. Create gradle application gradle init Select type of project to generate: 1: basic 2: application 3: library 4: Gradle plugin Enter selection (default: basic) [1..4] 2 Select implementation language: 1: C++ 2: Groovy 3: Java 4: Kotlin 5: Swift Enter selection (default: Java) [1..5] 4 Select build script DSL: 1: Groovy 2: Kotlin Enter selection (default: Kotlin) [1..2] 2 2. Add SomeJavaClass.java file beside App.kt file class SomeJavaClass{ public void m(){ System.out.println("x"); } } 3. Try to access SomeJavaClass in App.kt main method SomeJavaClass().m() Excepted Output: Should be able to run Actual Output: no compile issues but crash because of NoClassDefFoundError
g

gcx11

07/19/2020, 4:00 PM
@Praveen Talari Hello, default folder for Java classes is
src/main/java
folder. There are two possible solutions: • relocate Java sources to
src/main/java
folder • modify java sources location by adding following lines into
build.gradle.kts
sourceSets.main {
    java.srcDirs("src/main/kotlin")
}
👍 1
p

Praveen Talari

07/19/2020, 5:51 PM
Thanks, that's the issue. I forgot about the java folder. BTW, It should show compile time error, isn't it ? I have used the below in my Groovy build.gradle
sourceSets {
    main.kotlin.srcDirs = ['src/main/java', 'src/main/kotlin']
}
instead of all this, just renaming kotlin folder present inside src to "java" is the simplest solution. 😁