Pact-jvm: Pact java libraries are incompatible with java 9+ modules

Created on 24 Mar 2020  路  5Comments  路  Source: pact-foundation/pact-jvm

We are attempting to utilize Pact in a project which is based on java11 (java 11, gradle 6, JUnit 5 + Jupiter) and utilizes some a jigsaw module which is only within java 11 (requires java.net.http), and unfortunately we are stuck.

Upon further investigation (here is a useful article on DZone), it appears that the MANIFEST.MF for all of the java pact libraries includes an explicit entry to define an 'Automatic-Module-Name' per the following code:

See an example offending line of code in build.gradle currently in master on line 110:
'Automatic-Module-Name': project.group + "." + project.name

The problem is that the project.name includes hyphens, which are not allowed to be in java module names. Thus, whenever you try to include any of these Pact jars within a project which is built with Java 9 or higher, it fails.

A quick way to validate this problem is to execute the following command on _any of the Pact library jars_ (see example command/output):

$ jar --describe-module --file=./pact-jvm-consumer-junit5-4.0.8.jar
Unable to derive module descriptor for: .\pact-jvm-consumer-junit5-4.0.8.jar
Automatic-Module-Name: au.com.dius.pact-jvm-consumer-junit5: Invalid module name: 'pact-jvm-consumer-junit5' is not a Java identifier

A potential quick fix (before actually creating module-info.java descriptors for these libraries) could be to stop explicitly including the invalid 'Automatic-Module-Name' within the builds for these jars. I have not attempted to build any of the Pact libraries myself using Java 9+, however if I manually remove that 'Automatic-Module-Name' line from the embedded generated manifest file in the above jar, it stops complaining:

$ jar --describe-module --file=./pact-jvm-consumer-junit5-4.0.8.jar
No module descriptor found. Derived automatic module.

[email protected] automatic
requires java.base mandated
contains au.com.dius.pact.consumer.junit5

If anyone has some thoughts on a work-around for utilizing Pact to test project which must be built with Java 9 or higher, I would welcome the thoughts

All 5 comments

I've been using Java 12 without issues, but not Gradle 6. But I'll rename the module names to remove the hyphens.

Using underscores seems to work:

$ jar --describe-module --file=$HOME/.m2/repository/au/com/dius/pact-jvm-core-model/4.0.9/pact-jvm-core-model-4.0.9.jar
No module descriptor found. Derived automatic module.

[email protected] automatic
requires java.base mandated
contains au.com.dius.pact.core.model
contains au.com.dius.pact.core.model.annotations
contains au.com.dius.pact.core.model.generators
contains au.com.dius.pact.core.model.matchingrules
contains au.com.dius.pact.core.model.messaging

But I think all the modules and dependencies of this project need to be re-visited, but that would have to be for 4.1.x

Great, thank you very much @uglyog - this interim solution will help us a lot. Do you have an idea of when this will be released (4.0.9?) and pushed to maven central?

Version 4.0.9 released.

Was this page helpful?
0 / 5 - 0 ratings