scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Support for Java/Scala mixed compilation with `--server=false`

Open Gedochao opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. Mixed compilation of both .scala and .java files currently requires the usage of Bloop. Under --server=false .java files are ignored completely.

// Message.java
public class Message {
    private String message = "Hello, World!";
    Message(String message) {
        this.message = message;
    }
    public String getMessage() {
        return message;
    }
}
// Main.scala
@main def main() = println(new Message("Hello, mixed compilation").getMessage)
scala-cli . --server=false
# Exception in thread "main" java.lang.NoClassDefFoundError: Message
#         at Main$package$.main(Main.scala:1)
#         at main.main(Main.scala:1)
# Caused by: java.lang.ClassNotFoundException: Message
#         at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
#         at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
#         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
#         ... 2 more

Note that this works fine when Bloop is used.

scala-cli .               
# Compiling project (Scala 3.5.0, JVM (17))
# Compiled project (Scala 3.5.0, JVM (17))
# Hello, mixed compilation

Describe the solution you'd like Optimally, we'd like to support mixed compilation without using Bloop.

Describe alternatives you've considered If we can't support it, a good error message would be helpful.

Additional context

  • https://github.com/scala/scala3/issues/21533

Gedochao avatar Sep 23 '24 11:09 Gedochao