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

hamcrest-core and hamcrest-library are split packages #269

Closed
shs96c opened this issue Aug 19, 2019 · 6 comments
Closed

hamcrest-core and hamcrest-library are split packages #269

shs96c opened this issue Aug 19, 2019 · 6 comments

Comments

@shs96c
Copy link

shs96c commented Aug 19, 2019

It's great that these hamcrest jars (at version 1.3, which is what junit 4.12 depends on) declare an automatic module name so that they can be used with the JPMS, but there's a problem --- they create a "split package" since they both try and export classes in org.hamcrest This causes any java 9 modular build that includes both libraries to fail.

This can be fixed by making sure that all the classes in any package are in the same jar, so either by combining all the hamcrest jars, or by being careful with how the release artifacts are constructed.

@tumbarumba
Copy link
Member

Thanks for raising this issue, @shs96c. i'm not a heavy user of Java 9, so I'm not sure: is this still a problem with Hamcrest 2.1?

Hamcrest 2.1 was released as 3 jars: hamcrest-2.1.jar (now contains all the code), hamcrest-core-2.1.jar and hamcrest-library-2.1.jar (both empty shims to allow transitive depenencies to find hamcrest-2.1.jar). All 3 jars specify 'Automatic-Module-Name': 'org.hamcrest' in the manifest. I was under the impression that this would Just Work™ with Java 9 modules.

In nearly all cases, Hamcrest 2.1 can be a drop in replacement for Hamcrest 1.3 (though there are some quirks in upgrading: http://hamcrest.org/JavaHamcrest/distributables#upgrading-from-hamcrest-1x)

@shs96c
Copy link
Author

shs96c commented Aug 20, 2019

I don't think that'll work. The JPMS uses the module name to look up the jar to use, so if multiple jars share the same name there's some distinctly undefined behaviour. Having the core and library jars be empty should be fine, however.

I've bumped my hamcrest to 2.1, dropped the core and library deps, and (after losing @Factory and fixing up code to pretend it never happened) everything seems happier.

Still, the same module name everywhere is going to cause chaos.

@sf105
Copy link
Member

sf105 commented Aug 20, 2019 via email

@tumbarumba
Copy link
Member

If we modified the jars so that they had different values in Automatic-Module-Name, such as org.hamcrest, org.hamcrest.core and org.hamcrest.library, would that solve the issue? Would that cause other problems?

I should sit down and create a code sample to test this out.

@shs96c
Copy link
Author

shs96c commented Aug 20, 2019 via email

tumbarumba added a commit that referenced this issue Aug 24, 2019
Resolves issue #269. Changes the module name of hamcrest-core and
hamcrest-libary to avoid split package problems with Java 9.
@tumbarumba
Copy link
Member

I was able to reproduce this problem at https://github.com/tumbarumba/hamcrest-test-harness, and tested out the fix in PR #270, which Worked for Me™. Closing this issue on that basis.

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

3 participants