Skip to content
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

Modularize (java 9/11) lanterna #407

Closed
loic-prieto opened this issue Dec 7, 2018 · 12 comments
Closed

Modularize (java 9/11) lanterna #407

loic-prieto opened this issue Dec 7, 2018 · 12 comments

Comments

@loic-prieto
Copy link

Hi there!

Thanks for the excellent work you've been doing so far with the library. I'm using it to create a 4X framework (xDD), and it is helping me a lot :)

I'm trying to migrate to Java 11 from Java 8, and one of the benefits of doing that is to be able to create compact java images with jlink. But all of your dependencies must be modularized too in order to do that, no automodularized packages can be included in that image. Which means that unless all libraries I use are modularized, I'm "stuck" with deploying my java app the usual way.

So, my request would be to make lanterna a java module, with the module-info.java class and all of those things required to do that. I've been looking at the dependencies of lanterna itself, and it almost depends on nothing, which I think would make for a painless conversion to the module system.

Would that work for you?

Best regards,
Loïc Prieto.

@jrb0001
Copy link
Contributor

jrb0001 commented Dec 7, 2018

That sounds like a great idea. It should be possible to compile everything except module-info.java with -source/-target 1.6 to keep compatibility with older versions.

@mabe02
Copy link
Owner

mabe02 commented Dec 8, 2018

I'd be happy to, but I have no experience in Java 9+ so I'm not sure how to do this.

@mabe02
Copy link
Owner

mabe02 commented Dec 8, 2018

By the way, I'm also considering moving master branch to Java 8 finally. Not that it helps much with modules though.

@jrb0001
Copy link
Contributor

jrb0001 commented Dec 8, 2018

The minimal version doesn't matter for modularizing. As far as I know, you have to execute the maven-compiler-plugin twice, once with the minimal source/target version and excluding module-info.java and once with source/target 9 but for module-info.java.

@loic-prieto
Copy link
Author

I'm no expert myself. I'm currently struggling to migrate my app to Java11. It is proving to be challenging. The app itself is easy, but making the dependencies work and be able to test things and making them run on IntelliJ is very difficult. I'm running constantly into resource visibility issues.

I'm reading the following book: Java 9 Modularity
To try to make sense of it all.

@Nzen
Copy link

Nzen commented Jun 12, 2019

I'm of the understanding that lanterna has two options to accommodate requests for modular jars :

  1. Ensure that the resulting jar manifest has an entry with an Automatic-Module-Name . This is typically accomplished by adding an extra config to the maven jar plugin.
  2. Utilize two maven build profiles to build two separate jars. One will have the pre-java-9 compiler configuration; the other will have a post-java-9 compiler configuration. Releasing to a repository involves running maven twice, and changing either the artifact id or the version to distinguish which is which. For example, mvn release (assuming the default profile is j6-8) ; *change pom* ; mvn -P j9 release (assuming the modularized profile is called j9).

I can submit a pull request for either, but the decision lies more with the individual creating releases, given that this may change hiso'er workflow.

There's another aspect, albiet relevant to #422 : this project can create two jars, but there are classes for the same package in each, com.googlecode.lanterna.terminal. A modular runtime will reject one of those jars. For callers that desire both on jre 9 or later, y'all may need to either move the native integration classes to a different package or unite them with mainline.

@jrb0001
Copy link
Contributor

jrb0001 commented Jun 12, 2019

Automatic-Module-Name has the disadvantage that it doesn't work with jlink, which can create minimalistic runtime images based on the needs of the application.

There is also a third option:

  1. Use two compiler passes, the second for producing Java 9+ bytecode into META-INF/versions/9 (or whichever bytecode version you want to use). This will work on all runtime versions and is needed if you want to provide alternative versions of some classes for newer runtime versions (usually because of Unsafe or similar deprecated classes, there can be other reasons as well though).

@mabe02
Copy link
Owner

mabe02 commented Aug 19, 2019

That sounds promising, do you have any reference material on how to set this up?

@jrb0001
Copy link
Contributor

jrb0001 commented Aug 19, 2019

@mabe02 I have never actually tried it myself and all examples on the internet seem to call out to ant (ungh) so I decided to give it a try now. #429 is the third option mentioned above plus some small tweaks to support running without the java.desktop module.

@jrb0001
Copy link
Contributor

jrb0001 commented Aug 25, 2019

#429 has been merged into master. @mabe02 When can we expect a release with it to Maven Central?

@mabe02
Copy link
Owner

mabe02 commented Aug 28, 2019

Within a few weeks probably, I need to get the Java 8 migration working and also update all the themes to support the new menu functionality

@mabe02
Copy link
Owner

mabe02 commented Jan 11, 2020

lanterna-3.1.0-alpha1 has been released and pushed to Sonatype

@mabe02 mabe02 closed this as completed Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants