Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build.gradle: add javafx runtime dependency for all platforms
We have added the platform-specific javafx runtime dependencies, so the addressbook is able to run locally. However, the jar file generated on one OS cannot run on other OS. The reason is that, after detecting the OS, javafx will try to load platform-specific classes dynamically. Without corresponding javafx dependencies for that other OS, the class loading process will fail. Let's add the javafx runtime dependency for all platforms (MacOS, Window, Linux) so the jar file generated on one OS is able to run in other OS [1]. Following are some key facts that guarantee the solution to work: * Gradle places all dependency JARs on the classpath and the order is not defined by Gradle. * When shadowJar encounters duplicate classes with same package name and same class name, it picks the first one it sees. ShadowJar processes dependency JARs according to their order in classpath. * The platform-specific JARs for different OSs can define the same classes. (e.g. javafx-graphics-11-win.jar and javafx-graphics-11-linux.jar both contain javafx/scene/control/TreeView.class). However, via diffing the contents of the JARs, we have verified that if two JARs define the same class, the class files are also identical to each other. So, it doesn't matter if the TreeView.class from javafx-graphics-11-win.jar or the TreeView.class from javafx-graphics-11-linux.jar is loaded. As such, no matter what order Gradle places JavaFX's JARs on the classpath, we can run and distribute addressbook properly. [1] https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing/52654791#52654791
- Loading branch information