testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.05k stars 1.66k forks source link

error: module not found: testcontainers #5118

Closed ziccardi closed 2 years ago

ziccardi commented 2 years ago

Description

Hello guys, I have a module not found error in this branch: testcontainers.

The testcontainer dependency is added here and the module is required here

Any idea about what I am missing here?

Steps to reproduce

You can reproduce the error by cloning the repo, move to the testcontainers branch and run:

./gradlew build

My environment

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Mac OS X 10.16 x86_64

Thank you in advance!

bsideup commented 2 years ago

Seems to be there: https://repo1.maven.org/maven2/org/testcontainers/testcontainers/1.16.3/testcontainers-1.16.3.pom

make sure that your Gradle repositories are configured correctly.

ziccardi commented 2 years ago

Hi @bsideup ! I'm ok with you to close the issue, but the error wasmodule not found, not a gradle configuration issue.

By looking at the link I provided, you can see that the error is about a Java 9 module based project: I even provided a whole project you can clone to replicate the issue and see it is not a gradle misconfiguration.

I discussed with @kiview on slack about it: the problem is that since testcontainers doesn't have a Automatic-Module-Name in the metainf, gradle puts the jar into the unnamed module, which is not visible from named modules.

I worked around that by adding java9-modularity plugin to gradle to be able to use testcontainers as a named module. That worked for me because I used a custom docker image, but if you need to use one of the others Testcontainers deps you will get a split package error because different testcontainer artifacts are sharing the same package.

bsideup commented 2 years ago

Ah, I see. Well, Testcontainers isn't a Java Module. We are considering making it modular in 2.0.

See https://github.com/testcontainers/testcontainers-java/issues/521 & https://github.com/testcontainers/testcontainers-java/issues/1523 for more context.