Commit ae39206
committed
WIP: Attempt to JPMSify the scijava-ops-opencv tests
It does not quite work as written.
Here are some notes I wrote as I was developing this patch:
Adding a scijava-types dependency to main causes a weird problem where
the unit tests then fail to execute, due to a sudden inability to locate
classes from org.scijava.ops.api.
To fix the issue, I made a separate module-info.java for the tests, to
require the org.scijava.ops.api because the tests *do* need it.
Aside: one thing that's weird is we weren't depending on the jupiter
engine. So I just tried adding that. But the failures are the same.
The maven-surefire-plugin documentation has a page on running unit tests
for JPMS-enabled projects:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/jpms.html
The examples given there use a distinct module name for the test
module-info.java, and also require the main module. So I tried changing
the test module-info.java of this patch to be structured this way, with
its own module name (I appended .test), and moved the TestOpenCV class
into a test subpackage accordingly to avoid package clash across
multiple modules... but I get the same failures afterward. So I changed
it back to the same module declaration as the main module-info.java,
since that seems less broken.
I think the issue with kotlin is that scijava-io-http depends on okhttp
which depends on okio which depends on kotlin stuff (because okio is a
KMP project now), and scijava-io-http is an unnamed module without a
module-info.java. So we are stuck guessing how the module config should
look for that piece of our dependency tree, I suppose.
My guess is that when there is no module-info.java in the src/test, it
runs the tests outside JPMS, i.e. with a plain classpath. Whereas once
you have a test-side module-info, the surefire plugin thinks "ah, you
want to test this as a JPMS module, I should use a module path."
Which suggests to me that we are going to be in big trouble as soon as
anything downstream tries to use e.g. scijava-ops-opencv as a JPMS
module...
The fix might be a simple as just adding all the test scope dependencies
to the test module-info.java, as I should have but didn't.
I was able to get much closer to a working JPMS configuration for
scijava-ops-opencv, but the openblas native library dependency is not
something I know how to overcome.
The other crazy thing I had to do was exclude okio and explicitly add
only okio-jvm. Otherwise, JPMS gets confused about which JAR has the
okio module, since they both purport to have it (but really, only
okio-jvm has the needed classes).
I think the lesson here is: JPMS projects can't fully depend on
non-JPMSified projects that do unusual things, such as wrap native
libraries into JAR files and extract them. Or even non-JPMS-friendly
things, like having multiple JAR files with the same package prefix
and/or module name. I say "fully" depend because yeah, you can depend on
them, but if they don't work in a modular context, you'll be stuck using
your code only in a non-modular (i.e. classpath) style.
This is probably worth a forum post in Development category on the
forum, and a heads up to Tobias that JPMSifying ImgLib2 is going to
cause these headaches for any projects that have third party
dependencies. Getting things like BigWarp and SNT into JPMS is not going
to be feasible any time soon.
I noticed that okio 3.8.0 does not have this double-module-declaration
issue anymore. But upgrading to 3.8.0 still does not avoid the
`NoClassDefFound okio/Buffer`, for reasons I don't understand. I thought
it was happening because okio.jar had a clashing `Automatic-Module-Info`
line with okio-jvm, but nope, apparently that's not why. Excluding the
former JAR does fix the error though, so I dunno. I guess we could
exclude it in scijava-io-http and release a new version of that, so that
JPMS projects built on scijava-ops can use scijava-io-http more easily.
I found an SO post about exactly this JavaCPP + JPMS problem:
https://stackoverflow.com/a/71385521/1207769. However, I think the
solution detailed there boils down to passing `--add-modules
ALL-MODULE-PATH` to the test execution (if I'm reading it correctly),
which seems like not a proper solution.
Giving up for now.1 parent db58cef commit ae39206
4 files changed
Lines changed: 94 additions & 0 deletions
File tree
- scijava-ops-opencv
- src
- main/java
- org/scijava/ops/opencv
- test/java
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
128 | 140 | | |
129 | 141 | | |
130 | 142 | | |
| |||
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
152 | 169 | | |
153 | 170 | | |
154 | 171 | | |
| |||
171 | 188 | | |
172 | 189 | | |
173 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
174 | 204 | | |
175 | 205 | | |
176 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments