Skip to content

Add Java module definitions - #1028

Merged
andreaTP merged 13 commits into
dylibso:mainfrom
A248:java-module-defs
Nov 6, 2025
Merged

Add Java module definitions#1028
andreaTP merged 13 commits into
dylibso:mainfrom
A248:java-module-defs

Conversation

@A248

@A248 A248 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Aims to solve #1012

I added Java module definitions where I thought appropriate. Several of the subprojects aren't designed for external consumption, such as test suites and benchmarks.

Packages named "internal" I treated as internal to chicory, i.e. not intended for external consumption.

Additionally, I did my best to check when types from a dependency were exposed in a module's public API, in order to use requires transitive appropriately. It's possible I missed a spot, but this will never be breaking and will result in at most a compiler warning (on chicory's side) or the need to write another requires (on the library user's side).

Checkstyle

Chicory was still using checkstyle 9.3, which is still the default version in the maven-checkstyle-plugin. Because this old checkstyle version was running into problems consuming module-info.java, I increased the version to the latest.

This required checking for breaking changes in checkstyle, which I did by looking at every release since 9.3. Checkstyle does not follow SemVer so you have to look at every release notes.

Terminology

For people reading this PR, the PR itself targets the Java Modules introduced in Java 9. They are a separate concept from WASM modules.

@andreaTP andreaTP left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @A248 !
Much appreciated!

Skimming this from the phone seems reasonable, I'll have a closer look tomorrow.
Meanwhile I have a question is it possible to test the functionality somehow?

@A248

A248 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

Theoretically, yes. Some behavior is different on the module path: Java's ServiceLoader and ClassLoader.getResource(AsStream) are both affected by switching from an unnamed jar to a full module.

in practice, compilation will mostly ensure that the modules are declared properly. But if you want to spin up an integration test, you can always create a subproject that runs Chicory on the module path. This subproject can be created either as a plain Maven module, or using the maven-invoker-plugin.

Theoretically speaking though, there's no way to reach 100% coverage unless you literally fork all test runs and run them in a modular environment. That's why I rely on rg ServiceLoader and rg getResource when checking a codebase for the ability to use modules (using rg = ripgrep).

@andreaTP

Copy link
Copy Markdown
Collaborator

Thanks for the answer, I don't think we need 100% coverage, but an integration test to check that we are not badly messing up will be good...
I like the maven-invoker approach that's already used in this codebase, do you mind to add it to this PR?

@andreaTP

Copy link
Copy Markdown
Collaborator

@dmlloyd IIRC you played a bit with the module system, do you want to comment on this PR? 🙏

@dmlloyd dmlloyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptors themselves look fine, but I would ensure there is testing from the start.

Comment thread pom.xml
Comment on lines +557 to +559
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly is checkstyle failing on module-info?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module-info is wholly unsupported by checkstyle, so this is the recommended configuration (per their docs) to skip it.

checkstyle/checkstyle#8240

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'd put a comment in here to that effect though.

Comment thread pom.xml Outdated
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
<arg>-Xlint:-module</arg>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are module warnings disabled, specifically?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to make "internal" packages stay internal to Chicory, I added qualified exports like exports ....internal to othermodule;.

However, this causes a warning message like "module not found". This happens because the downstream module is not present during module compilation. To work around this, we'd need to either disable the lint -- or to restructure Chicory in ways that are very unstandard for a Maven build (1)

Because of <failOnWarnings>, the module-related warning message was failing the build, so I disabled itt.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment here too.

Comment thread pom.xml Outdated
@A248

A248 commented Sep 17, 2025

Copy link
Copy Markdown
Contributor Author

Good news! Not only did the tests caught a couple bugs, but they showed that the "internal" packages need to be exported after al. This obviates the need for -Xlint:-module and makes the PR overall more clean.

All that considered, I don't have any other changes in mind to make to this PR, besides addressing your review concerns, of course.

Comment thread compiler/pom.xml
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.sql</arg>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is surprising

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed by approval tests apparently, we should make sure this configuration only apply during tests

Comment thread wasm-corpus/pom.xml
@andreaTP

Copy link
Copy Markdown
Collaborator

I added a commit to disable checkstyle on Java 11, but now there is an issue with the modules.

Just to make sure I ask it: are those changes fully backward compatible?
E.g.: no changes are expected in user projects/code if they are not using the module system, correct?

@andreaTP

Copy link
Copy Markdown
Collaborator

Just to spell it out, I was waiting an iteration from you @A248 on this PR, let me know if you are going to have time to progress on it 🙂 and thanks again 🙏

@A248

A248 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Hi there, sorry for the delay. I took a look at the tests which were strangely failing on Java 11.

What's weird is that the approvaltests dependency jar contains .java source files alongside the classfiles. Javac is compiling these source files during test compilation. Why this only happens on Java 11 on the module path, but not in later Java versions, is beyond me.

Anyway, I'll hopefully get to the bottom of this and update this PR with the fix.

@A248

A248 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Potentially related: https://bugs.openjdk.org/browse/JDK-8338675 (javac modifies jar files when .java files are present inside them!)

@andreaTP

andreaTP commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

@dmlloyd if you have a spare cycle and are interested in having a look it would be appreciated 🙏

@dmlloyd

dmlloyd commented Oct 16, 2025

Copy link
Copy Markdown
Collaborator

The build is failing for me locally, but per that JDK bug I'd try adding -implicit:none to the maven-compiler-plugin arguments to javac.

@andreaTP

andreaTP commented Nov 6, 2025

Copy link
Copy Markdown
Collaborator

@A248 I want those fixes for the next release that is likely to happen soon, hence I took over this PR, I hope you don't mind.
Thanks a lot for your effort, LGTM!

@andreaTP
andreaTP merged commit f17e081 into dylibso:main Nov 6, 2025
26 checks passed
@andreaTP andreaTP mentioned this pull request Nov 6, 2025
@A248

A248 commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

All good! Thank you for taking over the PR.

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

Successfully merging this pull request may close these issues.

3 participants