Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROJECT JIGSAW – INTEGRATION WITH TOOLS

Similar presentations


Presentation on theme: "PROJECT JIGSAW – INTEGRATION WITH TOOLS"— Presentation transcript:

1 PROJECT JIGSAW – INTEGRATION WITH TOOLS
JavaOne SAN FRANCISCO Alexandru Jecan Software Engineer | Author | Trainer | Speaker | Consultant

2 SUMMARY 1 2 3 4 5 6 7 Integration with Build Tools Apache Maven
Maven Compiler Plugin 4 Maven Exec Plugin 5 Backward Compatibility Using Maven Toolchain Plugin Toolchain Plugin 6 Maven JDeps Plugin 7 Maven Jmod Plugin 02 PROJECT JIGSAW – INTEGRATION WITH TOOLS

3 SUMMARY 8 9 10 11 12 Maven Jlink Plugin Maven Dependency Plugin Gradle
Ant 12 Loom 03 PROJECT JIGSAW – INTEGRATION WITH TOOLS

4 SUMMARY 13 14 15 Moditect SonarJava Graphviz Gradle Ant Loom
04 PROJECT JIGSAW – INTEGRATION WITH TOOLS

5 SUMMARY 16 Integration with Integrated Development Environments 17 NetBeans support 18 Eclipse support 19 Intellij IDEA support 20 JDK 9 Ready Status 21 JDK 9 Ready Libraries 22 Status Modularization Third-party Libraries 05 PROJECT JIGSAW – INTEGRATION WITH TOOLS

6 SUMMARY 23 24 25 26 27 28 29 Modularized Third-party Libraries
How to Modularize a Library 25 Encapsulated JDK internal APIs 26 Not resolved platform modules 27 Cyclic dependencies 28 Split packages 29 Java 9 Modularity Revealed book 06 PROJECT JIGSAW – INTEGRATION WITH TOOLS

7 QUESTION What do you expect from a tool to do in order to make development using Jigsaw easier? 07 PROJECT JIGSAW – INTEGRATION WITH TOOLS

8 INTEGRATION WITH BUILD TOOLS
Jigsaw Build Tools Strong encapsulation Build the project Services Central repository Link into run-time images Dependency management Download artifacts Reliable configuration Record dependencies Record artifacts Verify at compile time and run time Verify for compilation Select artifacts for compilation The Java Module System, Nicolai Parlog, Manning 08 PROJECT JIGSAW – INTEGRATION WITH TOOLS

9 INTEGRATION WITH BUILD TOOLS
Prior to JDK 9 Build Tools Class path JDK 9+ Class path Build Tools Module path 09 PROJECT JIGSAW – INTEGRATION WITH TOOLS

10 APACHE MAVEN Only Maven 3+ supports Java 9
No changes were performed in Maven Core in order to make Maven run on Java 9 Maven can also use the module path for compilation (besides the class path) Normal modules as well as automatic modules can be defined as dependencies The presence of module-info.java decides if Maven uses the module path or not 10 PROJECT JIGSAW – INTEGRATION WITH TOOLS

11 APACHE MAVEN The <groupId>, <artifactId> and <version> from pom.xml are not related to the name of the module from module-info.java To add a dependency in pom.xml, the Maven specific names are used, as before To require a module in module-info.java, the name of the module from the module descriptors is used 11 PROJECT JIGSAW – INTEGRATION WITH TOOLS

12 MAVEN COMPILER PLUGIN Offers support for JPMS starting with version 3.6.0 Latest version = (as of September 2017) Requires JDK 7+ source and target have to be minimum 6 Module-info is compiled as well During the compile phase, when a module-info.java file is found, it automatically switches to the module path 12 PROJECT JIGSAW – INTEGRATION WITH TOOLS

13 MAVEN COMPILER PLUGIN Flags like --add-modules or --add-exports can be added directly in the pom.xml <compilerArgs> <arg>--add-modules</arg> <arg>java.xml.bind</arg> </compilerArgs> <compilerArgs> <arg>--add-exports</arg> <arg>java.base/sun.net=myModule</arg> </compilerArgs> 13 PROJECT JIGSAW – INTEGRATION WITH TOOLS

14 MAVEN COMPILER PLUGIN PROJECT JIGSAW – INTEGRATION WITH TOOLS
<artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <executions> <execution> <id>example</id> <goals> <goal>compile</goal> </goals> <configuration> <compilerArgs> <arg>--add-exports</arg> <arg>java.base/sun.net=myModule</arg> <arg>--add-modules</arg> <arg>java.xml.bind</arg> </compilerArgs> </configuration> </execution> </executions> </plugin> 14 PROJECT JIGSAW – INTEGRATION WITH TOOLS

15 MAVEN COMPILER PLUGIN A new tag called <release>, which has greater precendence over the <source> and <target> tags <release> corresponds to the option “maven.compiler.release” For providing backward compatibility: 1) Module-info should be compiled with --release 9 2) All the other sources compiled with --source < 9 and --target < 9 15 PROJECT JIGSAW – INTEGRATION WITH TOOLS

16 MAVEN EXEC PLUGIN Java 9 Modularity Sander Mak, Paul Bakker, O’Reilly
<groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.6.0</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>${JAVA_HOME}/bin/java</executable> <arguments> <argument>--module-path</argument> <modulepath/> <argument>--module</argument> <argument>{myMainClass}</argument> <argument>${myArgument}</argument> </arguments> </configuration> </plugin> Java 9 Modularity Sander Mak, Paul Bakker, O’Reilly 16 PROJECT JIGSAW – INTEGRATION WITH TOOLS

17 BACKWARD COMPATIBILITY WITH MAVEN TOOLCHAIN PLUGIN
Solves JEP 247: Compile for Older Platform Versions With toolchains, we can specify the JDKs installed on our system A project can be built using a specific version of the JDK that is independent from the one Maven is running with To use Toolchains: 1) The maven-toolchain-plugin should be adjusted 2) The toolchains.xml file should be adjusted 17 PROJECT JIGSAW – INTEGRATION WITH TOOLS

18 BACKWARD COMPATIBILITY WITH MAVEN TOOLCHAIN PLUGIN
Toolchains required when we have the module-info.java file inside the sources and we want to compile it with an older version of Java 18 PROJECT JIGSAW – INTEGRATION WITH TOOLS

19 MAVEN JDEPS PLUGIN discover all static dependencies of a library
JDeps can: discover all static dependencies of a library discover the usages of internal JDK APIs automatically generate a module descriptor for a JAR file Maven JDeps Plugin has two goals: jdkinternals => checks if main classes depend on JDK-internal classes test-internals => checks if test classes depend on JDK-internal classes 19 PROJECT JIGSAW – INTEGRATION WITH TOOLS

20 MAVEN JDEPS PLUGIN A compilation is necessary, since JDeps uses classes and not sources Should be used to test if your project is ready for JDK 9 By setting the <failOnWarning> option to true, the build will immediately fail if there are any warnings 20 PROJECT JIGSAW – INTEGRATION WITH TOOLS

21 MAVEN JDEPS plugin PROJECT JIGSAW – INTEGRATION WITH TOOLS
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jdeps-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>testOnClasses</id> <goals> <goal>jdkinternals</goal> <goal>test-jdkinternals</goal> </goals> </execution> <id>testOnDependencies</id> <configuration> <failOnWarning>false</failOnWarning> <recursive>true</recursive> </configuration> </executions> </plugin> 21 PROJECT JIGSAW – INTEGRATION WITH TOOLS

22 MAVEN JMOD PLUGIN Pre-release version (as of September 2017)
First version = alpha-1 Works with Maven 3+ and JDK 7+ Can create JMOD files (create goal) Can list the content of a JMOD file (list or describe goal) 22 PROJECT JIGSAW – INTEGRATION WITH TOOLS

23 MAVEN JLINK PLUGIN Pre-release version (as of September 2017)
First version = alpha-1 Works with Maven 3+ and JDK 7+ Can create Modular Run-Time Images via Jlink from jar /JMOD files (jlink goal) Has parameters like: <addModules>, <bindServices>, <compression>, <limitModules>, etc. 23 PROJECT JIGSAW – INTEGRATION WITH TOOLS

24 MAVEN DEPENDENCY PLUGIN
The list option lists the groupId, artifactId together with the name of the module 24 PROJECT JIGSAW – INTEGRATION WITH TOOLS

25 GRADLE Works since the --illegal-access=permit option was set as default No --add-opens options necessary to build Gradle No first class support for Java 9 modules as of Running Java 9 on Gradle 4.1+ is supported Example of producing a multi-release JAR with Gradle => Work in progress 25 PROJECT JIGSAW – INTEGRATION WITH TOOLS

26 ANT Ants java, javac and junit understand the new command-line parameters that are specific to JDK 9 modules Support for module path and upgrade module path added in Ant 1.9.7 Single module and multi module compilation supported Since Ant and : <java>, <javac> and <junit> support JDK 9 modules Support for javac --release option ant.java.version holds the value “9” 26 PROJECT JIGSAW – INTEGRATION WITH TOOLS

27 LOOM Modern and lightweight build tool for Java 9+ YAML configuration
Convention over configuration Build with Java 9 => first-class JPMS support (Optional) Minimalistic configuration Dependency resolution (powered by the Apache Maven Repository) Support for Junit 5, Checkstyle, SpotBugs, PMD, IntellijIDEA, Eclipse 27 PROJECT JIGSAW – INTEGRATION WITH TOOLS

28 LOOM https://loom.builders/
Loom source code => Loom documentation => Examples with Loom => 28 PROJECT JIGSAW – INTEGRATION WITH TOOLS

29 MODITECT https://github.com/moditect/moditect Maven plugin
Can generate module-info.java descriptors for given artifacts on behalf of the specific information written by developers in pom.xml Can add module descriptors to JAR files Can create modular runtime images 29 PROJECT JIGSAW – INTEGRATION WITH TOOLS

30 SonarJAVA Support for JPMS starting from version 4.11 Recognizes new keywords related to modules from Java 9 Able to recognize and parse module-info.java Can handle the directives from module-info.java: requires, exports, opens, uses and provides ModuleDeclaration: {Annotation} [open] module Identifier {. Identifier} { {ModuleDirective} } 30 PROJECT JIGSAW – INTEGRATION WITH TOOLS

31 GRAPHVIZ Example for Windows: Open source graph visualization software
Creates a graphical representation of Jigsaw modules and their dependencies: Example for Windows: jdeps -dotoutput jdeps-dotoutput modules/*.jar \Tools\Graphviz\release\bin\dot.exe –Tpng jdeps-dotoutput/summary.dot > graphviz-summary.png start graphviz-summary.png 31 PROJECT JIGSAW – INTEGRATION WITH TOOLS

32 INTEGRATION WITH INTEGRATED DEVELOPMENT ENVIRONMENTS
NetBeans Support Eclipse Support Intellij IDEA Support 32 PROJECT JIGSAW – INTEGRATION WITH TOOLS

33 NETBEANS SUPPORT NetBeans 9 runs on top of JDK 8 as well as JDK 9
Support for JDK 9 starting from NetBeans 9 NetBeans 9 not yet officialy released (as of ) NetBeans 9 runs on top of JDK 8 as well as JDK 9 Two options: 1) Build with Ant from: 2) Download the latest Development build from: JDK 8 is mandatory for building NetBeans 9; cannot use JDK 9 or JDK 7 or older 33 PROJECT JIGSAW – INTEGRATION WITH TOOLS

34 NETBEANS SUPPORT New Project Type => Java Modular Project
One NetBeans project now supports multiple Jigsaw modules Support for Maven projects Set netbeans_jdkhome in netbeans.conf to point to JDK 9 installation 34

35 NETBEANS SUPPORT Support for adding module-info (New =>Other => Java => Java Module Info) => supports code completion 35 PROJECT JIGSAW – INTEGRATION WITH TOOLS

36 NETBEANS SUPPORT Support for module path
Edit – Compile – Debug cycle supported 36 PROJECT JIGSAW – INTEGRATION WITH TOOLS

37 NETBEANS SUPPORT Go to Tools => Java Platforms and verify that it is running on JDK 9 Project property can be set to JDK 9 Source/binary format for files can be set to JDK 9 37 PROJECT JIGSAW – INTEGRATION WITH TOOLS

38 NETBEANS SUPPORT Module Dependency Graph using the Graph View
38 PROJECT JIGSAW – INTEGRATION WITH TOOLS

39 NETBEANS SUPPORT Support for packaging project files into a custom run-time using Jlink 39 PROJECT JIGSAW – INTEGRATION WITH TOOLS

40 NETBEANS SUPPORT JShell integration
40

41 ECLIPSE SUPPORT Eclipse Oxygen with Java 9 support
For Java 9 support, you can also update other Eclipse IDE to Eclipse 4.7. More info => 41 PROJECT JIGSAW – INTEGRATION WITH TOOLS

42 ECLISE SUPPORT Add JRE and JDK 9 as installed JRE
Support for JavaSE-9 execution environment Module compilation IDE can be launched with JDK 8 or JDK 9 Support for module path + class path 42 PROJECT JIGSAW – INTEGRATION WITH TOOLS

43 INTELLIJ IDEA SUPPORT Support for Jigsaw modules starting from version Enhancements in versions and Code completion in the module-info Each Jigsaw module has to correspond to an Intellij IDEA module For a module, “Mark directory as => Sources root” 43 PROJECT JIGSAW – INTEGRATION WITH TOOLS

44 INTELLIJ IDEA SUPPORT Supports module path, class path, module path + class path 44 PROJECT JIGSAW – INTEGRATION WITH TOOLS

45 INTELLIJ IDEA SUPPORT 45 PROJECT JIGSAW – INTEGRATION WITH TOOLS

46 INTELLIJ IDEA SUPPORT 46 PROJECT JIGSAW – INTEGRATION WITH TOOLS

47 Intellij idea support 47 PROJECT JIGSAW – INTEGRATION WITH TOOLS

48 INTELLIJ IDEA SUPPORT Package not exported => “Package not found”
No readability defined in module-info 48 PROJECT JIGSAW – INTEGRATION WITH TOOLS

49 INTELLIJ IDEA SUPPORT Recognizes when a platform module is not required Can suggest to add missing requires clauses in module-info 49

50 INTELLIJ IDEA SUPPORT Code completion in module-info
Code completion for exporting packages 50

51 INTELLIJ IDEA SUPPORT Both Intellij IDEA module dependencies as well as Jigsaw module dependencies have to be declared module com.javaone.application { requires com.javaone.service; } 51 PROJECT JIGSAW – INTEGRATION WITH TOOLS

52 INTELLIJ IDEA SUPPORT Dependency Diagram for Java 9
52 PROJECT JIGSAW – INTEGRATION WITH TOOLS

53 INTELLIJ IDEA SUPPORT Opens clause in open module not allowed
Duplicate clauses in module-info detected 53 PROJECT JIGSAW – INTEGRATION WITH TOOLS

54 INTELLIJ IDEA SUPPORT Find usages
54 PROJECT JIGSAW – INTEGRATION WITH TOOLS

55 INTELLIJ IDEA SUPPORT Inspection
Possibility to highlight the automatic modules, etc. 55 PROJECT JIGSAW – INTEGRATION WITH TOOLS

56 INTELLIJ IDEA SUPPORT Support for Maven projects
Automatically runs with the module path instead of class path Quick fixes for adding items in the module-info.java file 56 PROJECT JIGSAW – INTEGRATION WITH TOOLS

57 JDK 9 READY STATUS (AS OF 24.09.17)
57 PROJECT JIGSAW – INTEGRATION WITH TOOLS

58 JDK 9 READY LIBRARIES (AS OF 24.09.17)
Library Name JDK 9 Ready JDK 9 Ready starting from Version Apache Derby Yes Apache Log4j 2.9.0 Apache Lucene / Solr 7.0 (for both Lucene and Solr) Apache Maven 3.0 Apache PDFBox 2.0.8 Apache POI 3.17 bt CruiseControl GraphHopper 58 PROJECT JIGSAW – INTEGRATION WITH TOOLS

59 JDK 9 READY LIBRARIES (AS OF 24.09.17)
Library Name JDK 9 Ready HeapStats Yes Hibernate Jackson JaCoCo JITWatch JOSM Junit 5 LWJGL Rapidoid 59 PROJECT JIGSAW – INTEGRATION WITH TOOLS

60 JDK 9 READY LIBRARIES (AS OF 24.09.17)
Library Name JDK 9 Ready RedHat Wildfly Yes RxJava Spotbugs Woodstox 60 PROJECT JIGSAW – INTEGRATION WITH TOOLS

61 JDK 9 READY SOON LIBRARIES (AS OF 24.09.17)
Library Name Apache JMeter DataCleaner Golo JLine Roaring Apache MetaModel Drools Groovy Jboss-Forge Spring Framework Apache Tomcat EasyMock Hazelcast Kotlin ZXing Apache Tika Eclipse Jetty HSQLDB Objenesis Byteman Ehcache JavaEWAH OptaPlanner Classworlds ElasticSearch JBoss Tools oVirt engine 61 PROJECT JIGSAW – INTEGRATION WITH TOOLS

62 STATUS MODULARIZATION THIRD-PARTY LIBRARIES
62 PROJECT JIGSAW – INTEGRATION WITH TOOLS

63 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) Accumulo No ActiveMQ Ambari Ant Aurora Avro Axis Cassandra CloudStack Cordova CouchDB 63 PROJECT JIGSAW – INTEGRATION WITH TOOLS

64 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) EclipseLink No Falcon Flex Flume Geronimo Grails Groovy Guava Hadoop Hbase Hibernate 64 PROJECT JIGSAW – INTEGRATION WITH TOOLS

65 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) Jackrabbit No Jackson JDO Jersey Jetty Joda Jsoup Kafka Knox Log4j Lombok 65 PROJECT JIGSAW – INTEGRATION WITH TOOLS

66 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) Lucene No Mahout Maven Mesos Mockito Oozie OpenJPA Perl Pig PowerMock Quarz 66 PROJECT JIGSAW – INTEGRATION WITH TOOLS

67 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) SLF4J Yes Spark No Spring Struts Subversion SWT Tapestry TestNG Tiles Tomcat Vaadin 67 PROJECT JIGSAW – INTEGRATION WITH TOOLS

68 MODULARIZED THIRD-PARTY LIBRARIES
Library Name Modularized (as of ) Velocity No Xerces ZooKeeper 68 PROJECT JIGSAW – INTEGRATION WITH TOOLS

69 HOW TO MODULARIZE A LIBRARY
Modularize the codebase by introducing a module-info.java file for each module A module-info.java file can be: 1) Created manually by the developers 2) Automatically generated using the JDeps tool with the option --generate-module-info The most common four issues that can occur during the modularization of a library are: 1) Encapsulated JDK internal APIs 3) Cyclic dependencies 2) Not resolved modules 4) Split packages 69 PROJECT JIGSAW – INTEGRATION WITH TOOLS

70 ENCAPSULATED JDK INTERNAL APIS
Most of the internal JDK APIs are inaccessible in Java 9 Trying to access them causes a compilation error Internal APIs are in the sun.* package, but not only The module jdk.unsupported is still accessible: sun.misc.Unsafe, sun.reflect.Reflection, sun.misc.Signal, sun.reflect.ReflectionFactory, sun.misc.SignalHandler 70 PROJECT JIGSAW – INTEGRATION WITH TOOLS

71 ENCAPSULATED JDK INTERNAL APIS
Breaking encapsulation of the JDK Internal APIs: 71 PROJECT JIGSAW – INTEGRATION WITH TOOLS

72 NOT RESOLVED PLATFORM MODULES
Not all the platform modules from the JDK are available at compile-time All the packages from module java.se.ee are not available at compile-time: java.xml.ws, java.xml.bind, java.corba, java.activation, java.xml.ws.annotations => package not exist error encountered at compile-time 72 PROJECT JIGSAW – INTEGRATION WITH TOOLS

73 NOT RESOLVED PLATFORM MODULES
Solution: add the module that contains the needed packages in the graph of modules using the --add-modules options --add-modules java.xml.bind Use --add-modules both at compile-time and at run-time 73 PROJECT JIGSAW – INTEGRATION WITH TOOLS

74 CYCLIC DEPENDENCIES Forbidden at compile-time (between modules)
JPMS does not allow cycles in the “requires” clauses JPMS allows cycles in the “reads” relation of run-time modules module A { requires B; } module B { requires A; } 74 PROJECT JIGSAW – INTEGRATION WITH TOOLS

75 CYCLIC DEPENDENCIES One solution is to merge the JARs into a single module Redesign might be necessary to a higher degree Cycles can be broken by using interfaces 75 PROJECT JIGSAW – INTEGRATION WITH TOOLS

76 SPLIT PACKAGES Modules that contain packages having the same name must not interfere with each other Solutions for JAR files: Create a single JAR file out of the two JAR files Rename one of the package Solutions for modules: Create a single module out of two or more modules Create a third module Remove the package dependencies 76 PROJECT JIGSAW – INTEGRATION WITH TOOLS

77 Java 9 Modularity Revealed
Apress, 2017 221 pages ISBN:

78 @alexandrujecan alexandrujecan alexandrujecan.com


Download ppt "PROJECT JIGSAW – INTEGRATION WITH TOOLS"

Similar presentations


Ads by Google