testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Module support

Open zrbrown opened this issue 3 years ago • 0 comments

There's been discussion over the years of updating Testcontainers to work with Java modules (#1917, #1523, #1524), but not much movement on it as it's a breaking change. I'm submitting this PR to show the work that needs to be done to get this project working in a modular Java application.

First, split packages need to be fixed. Most modules were able to be fixed by just changed the org.testcontainers.containers part of the package to org.testcontainers.<modulename>. This did cause a few visibility issues, but I was surprised at how little package-private visibility was actually utilized! Besides package renaming, here are the other changes:

  • VncRecordingContainer::DEFAULT_RECORDING_FORMAT visibility was changed from package-private to public
  • GenericContainer::getWaitStrategy visibility was changed from protected to public
  • ContainerDatabaseDriver::getContainer visibility was changed from package-private to public
  • TrinoContainer::DEFAULT_TAG visibility was changed from package-private to public
  • PostgreSQLConnectionURLTest tests were modified to allow for access to the protected method constructUrlForConnection

Second, each module's build.gradle was modified to add an automatic module name. I'm not super well-versed in Gradle, so there may be a way to generalize the jar task to reduce clutter in each module's build file.

Both of these changesets are independent, but in the spirit of addressing Java modules, they're related.

This is obviously a breaking change (though it's not really that big of a change to consumers - all most will do is fix up imports), so it would need to target 2.0. I've seen discussion about a 2.0 (as well as a milestone), but as far as I can tell there isn't a branch to merge into. Since this project is used in tests, I personally wouldn't mind pulling in snapshot artifacts to use it if there were builds out there, but I can also see the headache in maintaining a branch where merges are more difficult due to package name changes. Thanks for any discussion on this!

zrbrown avatar Dec 28 '22 23:12 zrbrown