Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact java libraries are incompatible with java 9+ modules #1055

Closed
servionsolutions opened this issue Mar 24, 2020 · 5 comments
Closed

Pact java libraries are incompatible with java 9+ modules #1055

servionsolutions opened this issue Mar 24, 2020 · 5 comments

Comments

@servionsolutions
Copy link

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

@servionsolutions servionsolutions changed the title Pact java libraries are incompatible with java 9+ projects Pact java libraries are incompatible with java 9+ modules Mar 25, 2020
@uglyog
Copy link
Member

uglyog commented Mar 28, 2020

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

@uglyog
Copy link
Member

uglyog commented Mar 28, 2020

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

@uglyog
Copy link
Member

uglyog commented 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

@servionsolutions
Copy link
Author

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?

@uglyog
Copy link
Member

uglyog commented Apr 5, 2020

Version 4.0.9 released.

@uglyog uglyog closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants