question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pact java libraries are incompatible with java 9+ modules

See original GitHub issue

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.

au.com.dius.pactjvmconsumerjunit5@4.0.8 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, Apr 5, 2020

Version 4.0.9 released.

1reaction
uglyogcommented, Mar 28, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pact JVM 4.2.9 not compatible with Java 15 #1426 - GitHub
In the README of pact-jvm Github repo it says that 4.2.x is compatible with Java 11-15. But when I try to run my...
Read more >
Java 9 modules - 3rd party library dependency conflict
I have included two dependencies, protobuf-java and protobuf-lite, they both contains the same classes under the same packages (FQN), the ...
Read more >
Is the Java 9 module system supposed to solve dependency ...
This is not possible if you have (transitive) dependencies which both depend on incompatible versions of the library, but it's not a given...
Read more >
“How-to” Guides - Spring
Remember to add the Stub Runner and Spring Cloud Contract Pact modules as test dependencies. The following listing shows the configuration details for...
Read more >
Java 9 Migration Issues and Resolutions - Baeldung
In Java 9, this was streamlined with the introduction of the Java Platform Module System (JPMS), or Modules for short. Related packages were ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found