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.
-
Created an
interface Shape
-
Created two implementations
class Circle
andclass Square
ofinterface Shape
. -
Main
app
should havecompile-time
dependency oninterface Shape
, butruntime
dependency on implementations.
-
shape
-
This project has modules -
shape
,circle
andsquare
.
-
-
app
-
This project has main function.
-
This project has module with same name -
app
. -
It has implementation (compile) dependency on
shape
project.
-
-
shape
-
Module which has
interface Shape
. -
This module provides modules
Circle
andSquare
.
-
-
circle (Impl)
-
This module has
class Circle
which is implementation ofinterface Shape
.
-
-
square (Impl)
-
This module has
class Square
which is implementation ofinterface Shape
.
-
-
app
-
This module has the
main
method. -
It will use
getShape()
factory method in API, which will create objects ofCircle
andSquare
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.
-
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.
-
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". -
The gradle version "5.6.4" does not work with latest version of Java. So, using Java 11.
-
The gradle configurations are migrated to Kotlin Script. But for
app
project, I’m unable to set anext
property. So, I have reverted back to groovy file, which takes precedence over.kts
file. -
Top level
./gradlew build
was not working and needed explicit build ofshape
beforeapp
. Added a patch to force that order of task execution to make it work.