Skip to content

Scala throws 'Invalid module name' when running an application built with javafx and any scala jar containing underscore in its name #20049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
argotu1 opened this issue Mar 29, 2024 · 0 comments

Comments

@argotu1
Copy link

argotu1 commented Mar 29, 2024

Compiler version

Seem to be any version, tested it on 2.13.13, 3.3.3, 3.4.0 and 3.4.1

Minimized code

Strange thing is, Intellij IDEA runs this application without any problem, but when launching it via console (using the same command IDEA uses) or building with sbt-native-packager, the error occurs. Happens only if classpath contains jars with "_" symbol.

build.sbt:

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.4.1"

lazy val root = (project in file("."))
  .settings(
    name := "TestPackaging",
    libraryDependencies += "co.fs2" %% "fs2-core" % "3.10.1",
    libraryDependencies += "co.fs2" %% "fs2-io" % "3.10.1"
  ).enablePlugins(JavaAppPackaging)

Compile / unmanagedJars ++= {
  val base = baseDirectory.value
  val customJars = base / "../javafx-sdk-18/lib" ** "*.jar"
  customJars.classpath
}

MainApp.scala:

import javafx.application.Application
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.stage.Stage

object MainApp {
  def main(args: Array[String]): Unit = {
    Application.launch(classOf[MainApp], args*)
  }
}

class MainApp extends Application {
  override def start(stage: Stage): Unit = {
    val lbl = new Label("Hello, world")
    stage.setScene(new Scene(lbl))
    stage.show()
  }
}

Output

java.lang.module.FindException: Unable to derive module descriptor for ..\lib\co.fs2.fs2-core_3-3.10.1.jar
Caused by: java.lang.IllegalArgumentException: co.fs2.fs2.core.2.13: Invalid module name: '3' is not a Java identifier

Expectation

Application should not encounter any problems. I used the same configuration in the past and it worked just fine, so the issue might lie in newer version of sbt or Intelllij IDEA.

Update

Managed to fix the issue by editing ''META-INF/MANIFEST.MF'' inside every jar containing _3 in its name. Needed to append line "Automatic-Module-Name: ${new_module_name}" (provided it didn't have such line ). So, for example MANIFEST.MF for co.fs2.fs2-core_3-3.10.1.jar received one new line: "Automatic-Module-Name: co.fs2.fs2.core". New module name should follow package naming convention specified here. So, no hyphens, underscores or numbers instead of words. Needless to say all of this was extremely tedious, time-consuming and completely non-intuitive, so I would really like to see a more permanent and elegant solution implemented in sbt. I've seen there was some discussion about this and some solution apparently was implemented, but it doesn't work for each and every case, clearly

@argotu1 argotu1 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 29, 2024
@Gedochao Gedochao added compat:java and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants