-3

My project struct

("https://i.sstatic.net/EykkL.png")

Build.gradle content as below

apply plugin: 'java' apply plugin: 'kotlin' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" } sourceCompatibility = "1.7" targetCompatibility = "1.7" buildscript { ext.kotlin_version = '1.1.2-4' repositories { mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } repositories { mavenCentral() } // override the sourceSet flow other answers. sourceSets { main.java.srcDirs+= 'src/main/java' main.kotlin.srcDirs+= 'src/main/kotlin' main.resources.srcDirs += 'src/main/resources' } 

Exception when I run it

It may be compiled successfuly but when I run the kotlin codes. It throws the exception below. And the java codes run ok.

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at KotMainKt.main(kotMain.kt) Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more 
5
  • Please update your source code!.. Commented Jun 5, 2017 at 3:10
  • :kotlin-stdlib-jre8 doesn't like when you use sourceCompatibility = "1.7" Commented Jun 5, 2017 at 3:12
  • Do you run with kotlin stdlib on classpath? Commented Jun 5, 2017 at 3:36
  • I have modify the "sourceCompatibility=1.8",but it always don's run. Commented Jun 5, 2017 at 6:07
  • Android and kotlin-stdlib-jre8 don't really work together very well. Replace that will kotlin-stdlib and all should work Commented Jun 5, 2017 at 11:46

1 Answer 1

0

I add the codes belows at build.gradle and fix this problem.

Links:Configuring Gradle with Kotlin

jar { manifest { attributes 'Main-Class': 'KotMainKt' }

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 

}

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.