SlideShare a Scribd company logo
1 of 54
Java 9 and the impact
on Maven Projects
CGI / Robert Scholte - @rfscholte
#jfall16
© CGI Group Inc.
Java 9 and the impact on
Maven Projects
Robert Scholte (@rfscholte )
Chairman Apache Maven
“The success of Java 9 depends on the
adoption by IDEs and buildtools like
Maven”
Early Access releases
Jigsaw
• Since September 2015
• https://jdk9.java.net/jigsaw/
• ZIP
Java9
• Since April 2014
• https://jdk9.java.net/download/
• Executable
4
Challenge/Strategy Maven and Java9
• Support Maven 3.0 and above
• Only upgrades of plugins
Standard Java upgrade
Set Java Runtime for Maven
• JAVA_HOME=/path/to/jdk-9
Verify source/target of maven-compiler-plugin
• >= 6 (minimum jdk-9), okay
• < 6, must fork to preferred JDK
Maven JRE <> maven-compiler-plugin JDK
6
JEP 260: Encapsulate Most Internal APIs
Summary
Make most of the JDK's internal APIs inaccessible by default but leave a
few critical, widely-used internal APIs accessible, until supported
replacements exist for all or most of their functionality.
7
Results so far
• First java9-ea releases: close to no issues
• First jigsaw-ea release: ~99% of the Java Maven projects failed to
compile.
• Cause: JavacToolProvider + (System)Classloader
• Fixed and released within 72h!
• zero lines of code changed in Maven core codebase to run on Java9
8
~10% of JEPs related to Maven
• 220: Modular Run-Time Images *
• 223: New Version-String Scheme
• 226: UTF-8 Property Files
• 238: Multi-Release JAR Files
• 247: Compile for Older Platform Versions
• 261: Module System *
• 275: Modular Java Application Packaging (?)
• 282: jlink: The Java Linker *
* Part of JSR 376: Java Platform Module System (Project jigsaw)
9
Agenda
• 220: Modular Run-Time Images *
• 223: New Version-String Scheme
• 226: UTF-8 Property Files
• 238: Multi-Release JAR Files
• 247: Compile for Older Platform Versions
• 261: Module System *
• 275: Modular Java Application Packaging (?)
• 282: jlink: The Java Linker *
* Part of JSR 376: Java Platform Module System (Project jigsaw)
10
JEP 223: New Version-String Scheme
(project Verona)
Summary
Revise the JDK's version-string scheme so that it is easier to distinguish
major, minor, and security-update releases.
11
Major (GA) Example
12
System property Existing Proposed
java.version 1.9.0 9
java.runtime.version 1.9.0-b100 9+100
java.vm.version 1.9.0-b100 9+100
java.specification.version 1.9 9
java.vm.specification.version 1.9 9
version.split(“.”)[1]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.codehaus.plexus.archiver.zip.AbstractZipArchiver….
• maven-archiver-3.0.1
• maven-jar-plugin-3.0.0
• maven-war-plugin-3.0.0
• maven-ear-plugin-xxx
• maven-assembly-plugin-xxx
• maven-javadoc-plugin-2.10.4
• …
13
JEP 247: Compile for Older Platform Versions
Summary
Enhance javac so that it can compile Java programs to run on selected
older versions of the platform.
14
The problem
Leaking classes of the JDK
The official required javac arguments
• -source N
• -target N
• -bootclasspath <bootclasspath-from-N>
15
Available Maven Solutions (1)
• Always compile with the matching JDK version
• Configure maven-toolchain-plugin
• Configure toolchains.xml
• ${user.home}/.m2/toolchains.xml
• ${maven.home}/conf/toolchains.xml (since 3.3.1)
17
Available Maven Solutions (2)
• Verify code with jre signatures
• Configure animal-sniffer-maven-plugin
• Signature for N
• Execution-block with ‘check’ goal
18
Solution
“We defined a new command-line option, -release, which automatically
configures the compiler to produce class files that will link against an
implementation of the given platform version. For the platforms
predefined in javac, -release N is equivalent to
-source N -target N -bootclasspath <bootclasspath-from-N>.”
9-ea+135-jigsaw: --release (gnu-style)
19
maven-compiler-plugin 3.6.0
• Configuration: <release>N</release>
• Property: maven.compiler.release
• If source/target AND release are specified, release is used.
20
Forward compatibility
if ( javaVersion >= 1.8 ) {
// calculation based on Date-Time API (preferred)
}
else {
// calculation based on Date
}
source/target: 1.7
JDK: 1.8
JDK: 1.7 with reflection
22
JEP 238: Multi-Release JAR Files
Summary
Extend the JAR file format to allow multiple, Java-release-specific
versions of class files to coexist in a single archive.
23
JAR structure
jar root
- A.class
- B.class
- C.class
- D.class
- META-INF
- versions
- 9
- A.class
- B.class
- 10
- A.class
24
1 to 1 translation
project root
src/main/java
- A.java
- B.java
- C.java
- D.java
src/main/java9
- A.java
- B.java
src/main/java10
- A.java
Will work with Maven execution-blocks, not with (all) IDEs
25
IDE friendly POC
multimodule root
multirelease-base/src/main/java
- A.java
- B.java
- C.java
- D.java
multirelease-nine/src/main/java
- A.java
- B.java
multirelease-ten/src/main/java
- A.java
multirelease/src/assembly/mvjar.xml
https://github.com/hboutemy/maven-jep238
26
Improvements (in progress)
• Introduce new packaging (no install/deploy)
• Merge dependencies in JDK profiles
• Remove assembly descriptor
28
JEP 220: Modular Run-Time Images
Summary
Restructure the JDK and JRE run-time images to accommodate modules
and to improve performance, security, and maintainability. Define a new
URI scheme for naming the modules, classes, and resources stored in a
run-time image without revealing the internal structure or format of the
image. Revise existing specifications as required to accommodate these
changes.
29
Removal of tools.jar
Most Apache maven-plugins already have a lot of fallback scenarios for a
long time.
Projects that might suffer
• custom doclettags
• …
30
Tools.jar profile
<profile>
<id>default-tools.jar</id>
<activation>
<jdk>(,9)</jdk> <!-- System.getProperty( “java.version” ) -->
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
31
JEP 261: Module System
Summary
Implement the Java Platform Module System, as specified by JSR 376,
together with related JDK-specific changes and enhancements.
32
In a nutshell
module-info.java
• Specify exposed packages
• Specify required modules (buildtime + runtime)
• Specify usage and implementation of SPIs
33
Module Declarations Example (original proposal)
module M.N {
requires A.B;
requires public C.D;
requires static E.F;
requires public static G.H;
exports P.Q;
exports R.S to T1.U1, T2.U2;
exports dynamic PP.QQ;
exports dynamic RR.SS to T1.U1, T2.U2;
uses V.W;
provides X.Y with Z1.Z2;
provides X.Y with Z3.Z4;
}
34
Module Declarations Example (current proposal)
[|weak|open] module M.N {
requires A.B;
requires transitive C.D;
requires optional E.F;
requires transitive optional G.H;
exports P.Q;
exports R.S to T1.U1, T2.U2;
uses V.W;
provides X.Y with Z1.Z2;
provides X.Y with Z3.Z4;
}
35
Requires Modifier ‘transitive’
• A hint for other projects using this as dependency (no effect on this
project)
• Maven best practice: don’t trust transitive dependencies; specify
dependency for every used class
• Concept adopted by Java9:
• Modules are unaware of dependency tree
• All (non-transitive) modules MUST be specified
36
Requires Modifier ‘optional’
comparable with dependency.optional
Difference provided versus optional
• Buildtime: no difference
• Runtime:
• provided must be available (servlet-api)
• optional might be available (spring-boot deps)
37
Common usecases
38
maven-compiler-plugin 3.6.0
• :compile, switch to modulepath when compiling module-info.java
• :test-compile, switch to modulepath + classpath when
target/classes/module-info.class exists
39
Building Maven with Maven
40
Discover moduleName
• Documentation
• Central/Repository Managers? Archiva/Artifactory/Nexus
• maven-dependency-plugin:list
42
For library/framework/maven-plugin/… builders
• The lower the supported Java version, the more projects
can use it
• The lower the supported Java version, the less Java
features can be used.
Can we add module-info? Yes!
44
Backwards compatible libraries
• module-info (-release 9)
• (other) java sources (source/target < 9)
• Maven Recipe
45
Dependencies and classpath
• Classpath order:
• all direct dependencies
• all first level indirect dependencies
• all second level indirect dependencies
• …
• Locating a class:
• iterate over classpath (in same order); first match wins
46
Dependencies and modulepath
• Modulepath: packages are mapped to a module
• Duplicate packages will result in an Exception
• Locating a class:
• find module based on package; get class from module
47
GOTCHA: Dependency Excludes
‘requires’ means it is really required!
As enduser:
• No option to ignore requirements of third party libraries
• No option to fix/choose package collisions between transitive
dependencies
48
Java Platform Module System:Issue Summary
http://openjdk.java.net/projects/jigsaw/spec/issues/
49
Is my project Java9-ready?
• Is it using internal classes?
• maven-jdeps-plugin-3.0.0
• Does it have duplicate
• extra-enforcer-rule > banDuplicateClasses
• Does it require certain Java9 features
• Upgrade the matching plugins
50
The Apache Maven project tasklist
• Most features should work with Maven 3.0
• Some require Maven 3.3.1 due to improved toolchains support
• Large number of new features already developed in plugins, though
not always released.
• New recipes “The Maven Way™”
51
Developer awareness
• Maven-compiler-plugin selecting modulePath or/and classPath
• When Java9/Jigsaw fails:
• Usage internal APIs
• Duplicate (exported) packages
52
Thank you
Give it a try!
Send feedback, issues & wishes
“Please rate my talk in the
official J-Fall app”
#jfall16

More Related Content

What's hot

OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14Ivan Krylov
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9Deepu Xavier
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVMRyan Cuprak
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System IntroductionDan Stine
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Martin Toshev
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with MavenSid Anand
 
Managed Beans: When, Why and How
Managed Beans: When, Why and HowManaged Beans: When, Why and How
Managed Beans: When, Why and HowRussell Maher
 
Migrating to java 9 modules
Migrating to java 9 modulesMigrating to java 9 modules
Migrating to java 9 modulesPaul Bakker
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Workflow automation for Front-end web applications
Workflow automation for Front-end web applicationsWorkflow automation for Front-end web applications
Workflow automation for Front-end web applicationsMayank Patel
 

What's hot (19)

Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
 
OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14OpenJDK-Zulu talk at JEEConf'14
OpenJDK-Zulu talk at JEEConf'14
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Java 9 and Beyond
Java 9 and BeyondJava 9 and Beyond
Java 9 and Beyond
 
JDK-9: Modules and Java Linker
JDK-9: Modules and Java LinkerJDK-9: Modules and Java Linker
JDK-9: Modules and Java Linker
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
Java 9 modularity
Java 9 modularityJava 9 modularity
Java 9 modularity
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Maven
MavenMaven
Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Managed Beans: When, Why and How
Managed Beans: When, Why and HowManaged Beans: When, Why and How
Managed Beans: When, Why and How
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Migrating to java 9 modules
Migrating to java 9 modulesMigrating to java 9 modules
Migrating to java 9 modules
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Workflow automation for Front-end web applications
Workflow automation for Front-end web applicationsWorkflow automation for Front-end web applications
Workflow automation for Front-end web applications
 

Similar to Java9 and the impact on Maven Projects (JFall 2016)

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Robert Scholte
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG sessionMani Sarkar
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovJ On The Beach
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9haochenglee
 
Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1Kevin Sutter
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Martin Toshev
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesGlobalLogic Ukraine
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)Markus Günther
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Mihail Stoynov
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Robert Scholte
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterBoni García
 
Java dev mar_2021_keynote
Java dev mar_2021_keynoteJava dev mar_2021_keynote
Java dev mar_2021_keynoteSuyash Joshi
 

Similar to Java9 and the impact on Maven Projects (JFall 2016) (20)

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan Krylov
 
Modular Java
Modular JavaModular Java
Modular Java
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9
 
Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Gradle
GradleGradle
Gradle
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)
 
What's New in Java 9
What's New in Java 9What's New in Java 9
What's New in Java 9
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
 
Maven basic concept
Maven basic conceptMaven basic concept
Maven basic concept
 
Java dev mar_2021_keynote
Java dev mar_2021_keynoteJava dev mar_2021_keynote
Java dev mar_2021_keynote
 

More from Robert Scholte

Broken Buildtools and Bad Habits (Oracle Code One 2019)
Broken Buildtools and Bad Habits (Oracle Code One 2019)Broken Buildtools and Bad Habits (Oracle Code One 2019)
Broken Buildtools and Bad Habits (Oracle Code One 2019)Robert Scholte
 
Apache Maven supports ALL Java JEEConf 2019
Apache Maven supports ALL Java JEEConf 2019Apache Maven supports ALL Java JEEConf 2019
Apache Maven supports ALL Java JEEConf 2019Robert Scholte
 
Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Robert Scholte
 
Keeping up with Java made easy with Apache Maven (Devoxx 2018)
Keeping up with Java made easy with Apache Maven (Devoxx 2018)Keeping up with Java made easy with Apache Maven (Devoxx 2018)
Keeping up with Java made easy with Apache Maven (Devoxx 2018)Robert Scholte
 
Apache Maven and Java 9 and 10 (Devoxx France 2018)
Apache Maven and Java 9 and 10 (Devoxx France 2018)Apache Maven and Java 9 and 10 (Devoxx France 2018)
Apache Maven and Java 9 and 10 (Devoxx France 2018)Robert Scholte
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)Robert Scholte
 

More from Robert Scholte (6)

Broken Buildtools and Bad Habits (Oracle Code One 2019)
Broken Buildtools and Bad Habits (Oracle Code One 2019)Broken Buildtools and Bad Habits (Oracle Code One 2019)
Broken Buildtools and Bad Habits (Oracle Code One 2019)
 
Apache Maven supports ALL Java JEEConf 2019
Apache Maven supports ALL Java JEEConf 2019Apache Maven supports ALL Java JEEConf 2019
Apache Maven supports ALL Java JEEConf 2019
 
Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)
 
Keeping up with Java made easy with Apache Maven (Devoxx 2018)
Keeping up with Java made easy with Apache Maven (Devoxx 2018)Keeping up with Java made easy with Apache Maven (Devoxx 2018)
Keeping up with Java made easy with Apache Maven (Devoxx 2018)
 
Apache Maven and Java 9 and 10 (Devoxx France 2018)
Apache Maven and Java 9 and 10 (Devoxx France 2018)Apache Maven and Java 9 and 10 (Devoxx France 2018)
Apache Maven and Java 9 and 10 (Devoxx France 2018)
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Java9 and the impact on Maven Projects (JFall 2016)

  • 1. Java 9 and the impact on Maven Projects CGI / Robert Scholte - @rfscholte #jfall16
  • 2. © CGI Group Inc. Java 9 and the impact on Maven Projects Robert Scholte (@rfscholte ) Chairman Apache Maven
  • 3. “The success of Java 9 depends on the adoption by IDEs and buildtools like Maven”
  • 4. Early Access releases Jigsaw • Since September 2015 • https://jdk9.java.net/jigsaw/ • ZIP Java9 • Since April 2014 • https://jdk9.java.net/download/ • Executable 4
  • 5. Challenge/Strategy Maven and Java9 • Support Maven 3.0 and above • Only upgrades of plugins
  • 6. Standard Java upgrade Set Java Runtime for Maven • JAVA_HOME=/path/to/jdk-9 Verify source/target of maven-compiler-plugin • >= 6 (minimum jdk-9), okay • < 6, must fork to preferred JDK Maven JRE <> maven-compiler-plugin JDK 6
  • 7. JEP 260: Encapsulate Most Internal APIs Summary Make most of the JDK's internal APIs inaccessible by default but leave a few critical, widely-used internal APIs accessible, until supported replacements exist for all or most of their functionality. 7
  • 8. Results so far • First java9-ea releases: close to no issues • First jigsaw-ea release: ~99% of the Java Maven projects failed to compile. • Cause: JavacToolProvider + (System)Classloader • Fixed and released within 72h! • zero lines of code changed in Maven core codebase to run on Java9 8
  • 9. ~10% of JEPs related to Maven • 220: Modular Run-Time Images * • 223: New Version-String Scheme • 226: UTF-8 Property Files • 238: Multi-Release JAR Files • 247: Compile for Older Platform Versions • 261: Module System * • 275: Modular Java Application Packaging (?) • 282: jlink: The Java Linker * * Part of JSR 376: Java Platform Module System (Project jigsaw) 9
  • 10. Agenda • 220: Modular Run-Time Images * • 223: New Version-String Scheme • 226: UTF-8 Property Files • 238: Multi-Release JAR Files • 247: Compile for Older Platform Versions • 261: Module System * • 275: Modular Java Application Packaging (?) • 282: jlink: The Java Linker * * Part of JSR 376: Java Platform Module System (Project jigsaw) 10
  • 11. JEP 223: New Version-String Scheme (project Verona) Summary Revise the JDK's version-string scheme so that it is easier to distinguish major, minor, and security-update releases. 11
  • 12. Major (GA) Example 12 System property Existing Proposed java.version 1.9.0 9 java.runtime.version 1.9.0-b100 9+100 java.vm.version 1.9.0-b100 9+100 java.specification.version 1.9 9 java.vm.specification.version 1.9 9
  • 13. version.split(“.”)[1] Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 at org.codehaus.plexus.archiver.zip.AbstractZipArchiver…. • maven-archiver-3.0.1 • maven-jar-plugin-3.0.0 • maven-war-plugin-3.0.0 • maven-ear-plugin-xxx • maven-assembly-plugin-xxx • maven-javadoc-plugin-2.10.4 • … 13
  • 14. JEP 247: Compile for Older Platform Versions Summary Enhance javac so that it can compile Java programs to run on selected older versions of the platform. 14
  • 15. The problem Leaking classes of the JDK The official required javac arguments • -source N • -target N • -bootclasspath <bootclasspath-from-N> 15
  • 16.
  • 17. Available Maven Solutions (1) • Always compile with the matching JDK version • Configure maven-toolchain-plugin • Configure toolchains.xml • ${user.home}/.m2/toolchains.xml • ${maven.home}/conf/toolchains.xml (since 3.3.1) 17
  • 18. Available Maven Solutions (2) • Verify code with jre signatures • Configure animal-sniffer-maven-plugin • Signature for N • Execution-block with ‘check’ goal 18
  • 19. Solution “We defined a new command-line option, -release, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version. For the platforms predefined in javac, -release N is equivalent to -source N -target N -bootclasspath <bootclasspath-from-N>.” 9-ea+135-jigsaw: --release (gnu-style) 19
  • 20. maven-compiler-plugin 3.6.0 • Configuration: <release>N</release> • Property: maven.compiler.release • If source/target AND release are specified, release is used. 20
  • 21.
  • 22. Forward compatibility if ( javaVersion >= 1.8 ) { // calculation based on Date-Time API (preferred) } else { // calculation based on Date } source/target: 1.7 JDK: 1.8 JDK: 1.7 with reflection 22
  • 23. JEP 238: Multi-Release JAR Files Summary Extend the JAR file format to allow multiple, Java-release-specific versions of class files to coexist in a single archive. 23
  • 24. JAR structure jar root - A.class - B.class - C.class - D.class - META-INF - versions - 9 - A.class - B.class - 10 - A.class 24
  • 25. 1 to 1 translation project root src/main/java - A.java - B.java - C.java - D.java src/main/java9 - A.java - B.java src/main/java10 - A.java Will work with Maven execution-blocks, not with (all) IDEs 25
  • 26. IDE friendly POC multimodule root multirelease-base/src/main/java - A.java - B.java - C.java - D.java multirelease-nine/src/main/java - A.java - B.java multirelease-ten/src/main/java - A.java multirelease/src/assembly/mvjar.xml https://github.com/hboutemy/maven-jep238 26
  • 27.
  • 28. Improvements (in progress) • Introduce new packaging (no install/deploy) • Merge dependencies in JDK profiles • Remove assembly descriptor 28
  • 29. JEP 220: Modular Run-Time Images Summary Restructure the JDK and JRE run-time images to accommodate modules and to improve performance, security, and maintainability. Define a new URI scheme for naming the modules, classes, and resources stored in a run-time image without revealing the internal structure or format of the image. Revise existing specifications as required to accommodate these changes. 29
  • 30. Removal of tools.jar Most Apache maven-plugins already have a lot of fallback scenarios for a long time. Projects that might suffer • custom doclettags • … 30
  • 31. Tools.jar profile <profile> <id>default-tools.jar</id> <activation> <jdk>(,9)</jdk> <!-- System.getProperty( “java.version” ) --> </activation> <dependencies> <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.4.2</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> </dependencies> </profile> 31
  • 32. JEP 261: Module System Summary Implement the Java Platform Module System, as specified by JSR 376, together with related JDK-specific changes and enhancements. 32
  • 33. In a nutshell module-info.java • Specify exposed packages • Specify required modules (buildtime + runtime) • Specify usage and implementation of SPIs 33
  • 34. Module Declarations Example (original proposal) module M.N { requires A.B; requires public C.D; requires static E.F; requires public static G.H; exports P.Q; exports R.S to T1.U1, T2.U2; exports dynamic PP.QQ; exports dynamic RR.SS to T1.U1, T2.U2; uses V.W; provides X.Y with Z1.Z2; provides X.Y with Z3.Z4; } 34
  • 35. Module Declarations Example (current proposal) [|weak|open] module M.N { requires A.B; requires transitive C.D; requires optional E.F; requires transitive optional G.H; exports P.Q; exports R.S to T1.U1, T2.U2; uses V.W; provides X.Y with Z1.Z2; provides X.Y with Z3.Z4; } 35
  • 36. Requires Modifier ‘transitive’ • A hint for other projects using this as dependency (no effect on this project) • Maven best practice: don’t trust transitive dependencies; specify dependency for every used class • Concept adopted by Java9: • Modules are unaware of dependency tree • All (non-transitive) modules MUST be specified 36
  • 37. Requires Modifier ‘optional’ comparable with dependency.optional Difference provided versus optional • Buildtime: no difference • Runtime: • provided must be available (servlet-api) • optional might be available (spring-boot deps) 37
  • 39. maven-compiler-plugin 3.6.0 • :compile, switch to modulepath when compiling module-info.java • :test-compile, switch to modulepath + classpath when target/classes/module-info.class exists 39
  • 41.
  • 42. Discover moduleName • Documentation • Central/Repository Managers? Archiva/Artifactory/Nexus • maven-dependency-plugin:list 42
  • 43.
  • 44. For library/framework/maven-plugin/… builders • The lower the supported Java version, the more projects can use it • The lower the supported Java version, the less Java features can be used. Can we add module-info? Yes! 44
  • 45. Backwards compatible libraries • module-info (-release 9) • (other) java sources (source/target < 9) • Maven Recipe 45
  • 46. Dependencies and classpath • Classpath order: • all direct dependencies • all first level indirect dependencies • all second level indirect dependencies • … • Locating a class: • iterate over classpath (in same order); first match wins 46
  • 47. Dependencies and modulepath • Modulepath: packages are mapped to a module • Duplicate packages will result in an Exception • Locating a class: • find module based on package; get class from module 47
  • 48. GOTCHA: Dependency Excludes ‘requires’ means it is really required! As enduser: • No option to ignore requirements of third party libraries • No option to fix/choose package collisions between transitive dependencies 48
  • 49. Java Platform Module System:Issue Summary http://openjdk.java.net/projects/jigsaw/spec/issues/ 49
  • 50. Is my project Java9-ready? • Is it using internal classes? • maven-jdeps-plugin-3.0.0 • Does it have duplicate • extra-enforcer-rule > banDuplicateClasses • Does it require certain Java9 features • Upgrade the matching plugins 50
  • 51. The Apache Maven project tasklist • Most features should work with Maven 3.0 • Some require Maven 3.3.1 due to improved toolchains support • Large number of new features already developed in plugins, though not always released. • New recipes “The Maven Way™” 51
  • 52. Developer awareness • Maven-compiler-plugin selecting modulePath or/and classPath • When Java9/Jigsaw fails: • Usage internal APIs • Duplicate (exported) packages 52
  • 53. Thank you Give it a try! Send feedback, issues & wishes
  • 54. “Please rate my talk in the official J-Fall app” #jfall16