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
7.96k stars 1.64k forks source link

Include docker-java-api in BOM #4392

Open electrum opened 3 years ago

electrum commented 3 years ago

docker-java-api is part of the (advanced) public API of Testcontainers and thus it seems appropriate and helpful to have it be part of the BOM.

In my use case, I wanted to override GenericContainer.containerIsStarted(), which means I have a compile time dependency on InspectContainerResponse(as it is a parameter) and thus must declare a dependency on docker-java-api.

The problem is that I need to supply a version for the dependency, but what version do I use use? The answer is that it must be the same version as used by Testcontainers, but there's no way to do it automatically, so I have to manually copy/paste the version and keep it updated whenever I update Testcontainers. If it was in the BOM, I could simply add the dependency without a version and it would always be correct.

bsideup commented 3 years ago

Hi @electrum,

and thus must declare a dependency on docker-java-api

docker-java-api is a transitive dependency: https://mvnrepository.com/artifact/org.testcontainers/testcontainers/1.16.0

Which means that you get it automatically when you add testcontainers as a dependency if you are using a build system (Gradle/Maven/SBT/etc).

electrum commented 2 years ago

Hi @bsideup, thanks for the response and all your work on this great project.

You get the transitive dependency automatically, but if you use one of the Testcontainers methods such as GenericContainer.withCreateContainerCmdModifier() that requires using docker-java-api classes, the best practice is to add a direct dependency.

Using a transitive dependency directly in your code without declaring it is flagged by the Maven Dependency Plugin and likely by other build systems as well. Some build systems will actually prevent non-direct dependencies from being available to the compiler. Example:


[INFO] --- maven-dependency-plugin:3.1.2:analyze-only (default) @ my-module ---
[WARN] Used undeclared dependencies found:
[WARN]    com.github.docker-java:docker-java-api:jar:3.2.11:compile