7

I would like to use jlink for creating self-contained application packages for all platforms (darwin, linux, windows) from Scala source code. It seems that jlink only works with new (relatively) jigsaw modules - so I need to package my code as a module. In Java world it seems to be easily achieved by placing special module-info.java file to the package that will become a module.

I tried to follow intuition and just placed this module-info.java into src/main/java/my.package.name/module-info.java. Though this doesn't work. It seems that scalac is trying to read module-info.java as usual Java file (which is not the case), hence the error

module-info.java:1:8: illegal start of type declaration
[error] module my.package.name {
[error]        ^

What do I need to do to package my Scala code as a module?

Open JDK: 11 Scala: 2.12.4 SBT: 1.1.6

Naman
  • 27,789
  • 26
  • 218
  • 353
vladimir
  • 2,635
  • 3
  • 23
  • 26
  • 1
    If scalac doesn't know anything about modules then you might have to compile the module-info.java separately, with javac -d specifying the output directory where the scalac compiler has emitted the class files for the contents of the module. – Alan Bateman Nov 20 '18 at 08:46

1 Answers1

4

In general seems like that scala doesn't completely support Java9+, at least their compatibility notes read so.

As of Scala 2.12.6 and 2.11.12, JDK 9+ support is incomplete. Notably, scalac will not enforce the restrictions of the Java Platform Module System, which means that code that typechecks may incur linkage errors at runtime. Scala 2.13.x will provide rudimentary support for this, but likely only in nightlies built on Java 11.

You can follow Support features of JDK 9+ and Java 11 testing for further updates.

Naman
  • 27,789
  • 26
  • 218
  • 353