Weird jar problem


#1

I’m facing a case where I can’t import a toplevel function from a jar file (bad.jar) while I can from another one (good.jar).

The function is defined in BuildScript.kt:

@Directive public fun repos(vararg repos: kotlin.String): kotlin.Unit {...

When I compile with good.jar on the classpath, “import com.beust.kobalt.repos” compiles but not when I use bad.jar.

I verified that both jar files have this .class and function:

$ javap -classpath ~/t/bad.jar com.beust.kobalt.BuildScriptKt
Compiled from "BuildScript.kt"
public final class com.beust.kobalt.BuildScriptKt {
  public static final void repos(java.lang.String...);
}

$ javap -classpath ~/t/good.jar com.beust.kobalt.BuildScriptKt
Compiled from "BuildScript.kt"
public final class com.beust.kobalt.BuildScriptKt {
  public static final void repos(java.lang.String...);
}

BuildScriptKt.class is actually identical in both jar files.

It seems there is some external factor that is not exposing this function in bad.jar. I thought main.kotlin_module might have something to do with it so I copied that file from good.jar to bad.jar but that didn’t fix the problem.

What am I missing?


#2

Problem solved.

This was caused by the fact bad.jar is created from two small jar files but each of them was compiled with the default module name, so each creates a main.kotlin_module but only one of these two files ends up in bad.jar.

Temporary fix: make sure each jar file is compiled with a different module name.

I’ll file a an issue on YouTrack about this, this can trip people.