JavaOne – Building and Testing Java 9 Applications with Gradle

“Building and Testing Java 9 Applications with Gradle”

Speaker: Cédric Champeau
Deck on GitHub

For more blog posts from JavaOne, see the table of contents


General

  • First version of Java that is not backward compatible
  • Did review of Java 9 modules
  • Gradle can run on Java 8 or 9.
  • No built in support for module path
  • Some plugins don’t work – ex: FindBugs. Will be hard to figure out if plugin or Gradle’s fault. Some mocking frameworks will require upgrade as well.
  • Gradle 3.4 introduce a Java library plugin so can separate API and implementations dependencies. Just like modules!

Migrating to Java 9

  • Sample app with 6 modules
  • Uses reflection and service loader code so non trivial
  • implementation (requires) vs api (transitive ok) – paves way for Java 9
  • Replace META-INF/services with “provides” in module-info

Testing

  • want to compile main and tests separately. is that one or two modules? if two modules, prevent from seeing each other.
  • hack the java compiler task to give it the classpath as module path
  • use a patch module so main and test code are one module and the tests can access the package private classes. Also gives JUnit the right to read the classes.
  • so still compile separately but create one module

Automatic modules

  • “How many of you have a jar named util.jar?”
  • Reserve automatic module name now by setting Automatic-Module-Name in the manifest
  • They when upgrade to Java 9, use that name

Multi-Release Jars

  • Said multi-release jars are a bad idea because odds are low the dependencies are the same
  • Old way was to use reflection to determine which version available
  • /src/main/java – shared sources
  • /src/main/java9 – java 9 specific sources
  • Tell gradle which versions of Java to compile each with and differences in dependencies
  • ex: java9Implementation for dependencies – points it to shared sources

Future

  • Working on experimental jigsaw plugin which takes care of various tweaks demoed today. org.gradle.java.experimental-jigsaw

My take: This was interesting. I was a little distracted because I realized I needed to figure out a few presentation things for a larger room. So I was doing a little setup on my computer for tomorrow. It was hard to multi-task though. Cédric’s presentation was good and kept pulling me in :). Also the story teller app was cute. So I wasn’t satisfied in my level of paying attention or my level of getting ready for tomorrow. Oh well. I proved the downsides of “multi-tasking”.

Leave a Reply

Your email address will not be published. Required fields are marked *