spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Fix Freshmark compatibility with JDK 15+ (fixes #803)

Open beegee1 opened this issue 2 years ago • 4 comments

beegee1 avatar Sep 02 '22 15:09 beegee1

Hi @nedtwigg, I've implemented the functionality as you've described in https://github.com/diffplug/spotless/issues/803 , but unfortunately it is not working. The Nashorn library is provided as a JPMS module with a module descriptor file. The service provider infrastructure does not automatically pick up the library's implementation of the script engine. Furthermore, I guess JDK9+ rejects loading the classes from the lib as the --module-path and --add-modules arguments are missing.

Some more information: https://stackoverflow.com/questions/65265629/how-to-use-nashorn-in-java-15-and-later https://stackoverflow.com/questions/46288170/is-it-possible-to-mix-class-path-and-module-path-in-javac-jdk-9/46289257#46289257 https://github.com/openjdk/nashorn/blob/main/src/org.openjdk.nashorn/share/classes/module-info.java#L163

This describes how a possible solution could look like: https://stackoverflow.com/questions/48742354/best-approach-to-dynamically-load-modules-classes-in-java Modifying the module path layer, could work, but I cannot directly access these classes as the library must be compatible with Java 8 compilation. Reflection could be used, but hard to read.

beegee1 avatar Sep 05 '22 08:09 beegee1

This is a good answer how to load a JPMS module dynamically: https://stackoverflow.com/questions/62742150/how-do-i-dynamically-load-modules-from-a-directory-in-java-9

beegee1 avatar Sep 05 '22 08:09 beegee1

Should loading the Nashorn library/module be implemented with reflection or should another small lib be implemented which uses Java9+ and is loaded dynamically into the classpath and then a static method is called to load the Nashorn module?

beegee1 avatar Sep 05 '22 08:09 beegee1

Thanks so much for tackling this!

should... be implemented with reflection or should another small lib

  • I don't want Spotless to maintain another small lib
  • Reflection is fine
  • Using something like #524 is probably easier

Another possible approach is to look at

  • #1224
  • #1228

They are two PR's but should have been one.

nedtwigg avatar Sep 13 '22 18:09 nedtwigg

Thanks very much @beegee1 for getting this started! Fixing this required making a silly little change in an upstream project.

  • https://github.com/diffplug/jscriptbox/pull/3

nedtwigg avatar Feb 05 '23 09:02 nedtwigg

Released in plugin-gradle 6.14.1.

nedtwigg avatar Feb 05 '23 17:02 nedtwigg