cbeust / kobalt

A Kotlin-based build system for the JVM.
Apache License 2.0
432 stars 60 forks source link

Build fails for kotlin project in custom directory #473

Closed dimsuz closed 6 years ago

dimsuz commented 6 years ago

To reproduce just clone this project and execute

$ ./kobaltw assemble && ./kobaltw run

Output:

ERROR
Error: Could not find or load main class com.example.MainKt

I am able to reproduce both with 105 and 106 versions of Kobalt.

How I arrived at this project is I wanted to have a custom source directory. So I basically just did:

$ mkdir ~/kobalt-bug; cd ~/kobalt-bug
$ ./kobaltw --init kotlin
$ mkdir customdir
$ mv src/ customdir/

So now I have ./customdir/src/main/kotlin/com/example/Main.kt Next I edited Build.kt of this project to contain directory = "customdir".

And now kobalt is still able to build it, but seems like it ignores Main.kt completely and trying to run causes an error.

dimsuz commented 6 years ago

Oh, I forgot to mention. I have kotlin-1.2.10 in my settings.xml, due to the infamous kotlin compiler bug :). Dunno if this is related. Without it I cannot even compile. But I set Build.kt to have 1.2.10 deps too...

$ cat ~/.config/kobalt/settings.xml 
<kobaltSettings>
    <kobaltCompilerVersion>1.2.10</kobaltCompilerVersion>
</kobaltSettings>
dimsuz commented 6 years ago

I also want to note that without specifying a custom directory a project created by ./kobaltw --init kotlin builds and runs just fine. As soon as described modifications are done - it stops running.

dimsuz commented 6 years ago

OK, I believe I have found why this bug happens. I ran kobaltw run --log 3:

  Invoking separate kotlinc:
  /usr/lib/jvm/java-8-jdk/bin/java -classpath /home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.2.10/kotlin-compiler-embeddable-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-script-runtime/1.2.10/kotlin-script-runtime-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/annotations/13.0/annotations-13.0.jar:/home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-stdlib/1.2.10/kotlin-stdlib-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-reflect/1.2.10/kotlin-reflect-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.2.10/kotlin-compiler-embeddable-1.2.10.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -no-stdlib -classpath /home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-stdlib/1.2.10/kotlin-stdlib-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/kotlin/kotlin-runtime/1.2.10/kotlin-runtime-1.2.10.jar:/home/dima/.kobalt/cache/org/jetbrains/annotations/13.0/annotations-13.0.jar -d /home/dima/projects/kobalt-bug/kobaltBuild/classes customdir/src/main/kotlin

Notice this:

-d /home/dima/projects/kobalt-bug/kobaltBuild/classes

So it outputs classes to the root project dir. But assemble task expects to find them in customdir:

Creating customdir/kobaltBuild/libs/kobalt-bug-0.1.jar
Added 1 files to customdir/kobaltBuild/libs/kobalt-bug-0.1.jar

(this 1 file is MANIFEST.MF, so it doesn't count). So assemble task doesn't find the build MainKt.class - which is indeed can be found at $PROJECT_ROOT/kobaltBuild/classes/MainKt.class path

cbeust commented 6 years ago

Should be fixed in 1.0.107. Run ./kobaltw --update and then ./kobaltw run again.

dimsuz commented 6 years ago

Yay, it works now! Thank you for the fix.

avently commented 6 years ago

@cbeust I created a new kotlin project and i'm getting the same error: Could not find or load main class com.avently.testapp.Main

Inside a jar i see com/avently/testapp/MainKt.class but inside manifest of the jar this line: Main-Class: com.avently.testapp.Main

So i'm unable to start the app with ./kobalt run or with java filename.jar. What to do?

Upd: Cleaned the project after renaming Main to MainKt in build config and now it works fine.

cbeust commented 6 years ago

The class should be called MainKt.