Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create jigsaw module in SBT?

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

like image 783
vladimir Avatar asked Nov 19 '18 22:11

vladimir


1 Answers

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.

like image 82
Naman Avatar answered Oct 28 '22 01:10

Naman