Skip to content

Kotlin + Gradle for Java 9 - JPMS (Java Platform Module System)

License

Notifications You must be signed in to change notification settings

vihangpatil/kotlin-modules

Repository files navigation

Kotlin + Gradle for Java 9 - JPMS (Java Platform Module System)

Build Status Kotlin version badge GitHub license

This is a sandbox Kotlin app created to test out Java 9' Project Jigsaw functionality with Gradle.

For Project Jigsaw, without gradle, check this tutorial:
http://openjdk.java.net/projects/jigsaw/quick-start

For Maven, check my other repo:
https://github.com/vihangpatil/java-modules

I have used the ServiceLoader API and have used default constructors for implementing classes.

Experiment

  • Created an interface Shape

  • Created two implementations class Circle and class Square of interface Shape.

  • Main app should have compile-time dependency on interface Shape, but runtime dependency on implementations.

Gradle Projects

  1. shape

    • This project has modules - shape, circle and square.

  2. app

    • This project has main function.

    • This project has module with same name - app.

    • It has implementation (compile) dependency on shape project.

Modules

  1. shape

    • Module which has interface Shape.

    • This module provides modules Circle and Square.

  2. circle (Impl)

    • This module has class Circle which is implementation of interface Shape.

  3. square (Impl)

    • This module has class Square which is implementation of interface Shape.

  4. app

    • This module has the main method.

    • It will use getShape() factory method in API, which will create objects of Circle and Square using ServiceLoader API.

    • Try to uncomment the lines which are trying to use Circle class at compile-time. It should give a compile-time error.

Conclusion

app project, which has app module, has implementation (compile) dependency on shape project.
So, main method in app module is only able to access Shape interface at compile-time.
Circle and Square are not accessible since they are in different module.

The implementations Circle and Square are provided to app module by shape module.

Limitations

  1. org.gradle.java.experimental-jigsaw plugin has stopped working with latest version of gradle. So, added gradle wrapper to lock the gradle version to "5.6.4".

  2. The gradle version "5.6.4" does not work with latest version of Java. So, using Java 11.

  3. The gradle configurations are migrated to Kotlin Script. But for app project, I’m unable to set an ext property. So, I have reverted back to groovy file, which takes precedence over .kts file.

  4. Top level ./gradlew build was not working and needed explicit build of shape before app. Added a patch to force that order of task execution to make it work.

About

Kotlin + Gradle for Java 9 - JPMS (Java Platform Module System)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published