Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
steps:
- checkout
- run:
command: ./gradlew --no-daemon --continue --scan testcontainers:test --tests '*GenericContainerRuleTest'
command: ./gradlew --no-daemon --continue --scan testcontainers:test --tests '*GenericContainerRuleTest' testcontainers:jarFileTest
- run:
name: Save test results
command: |
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ shadowJar {
task jarFileTest(type: Test) {
useJUnitPlatform()
testClassesDirs = sourceSets.jarFileTest.output.classesDirs
classpath = sourceSets.jarFileTest.runtimeClasspath
classpath = sourceSets.jarFileTest.runtimeClasspath + configurations.runtimeClasspath

inputs.files(shadowJar).withPathSensitivity(PathSensitivity.RELATIVE)
systemProperty("jarFile", project.projectDir.toPath().relativize(shadowJar.outputs.files.singleFile.toPath()).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -38,6 +41,30 @@ void testMetaInfServices() throws Exception {
.allMatch(it -> it.startsWith("org.testcontainers."));
}

@Test
void testShadedMapperReadsPublicDockerModelAnnotations() throws Exception {
URL jar = Paths.get(System.getProperty("jarFile")).toUri().toURL();
try (URLClassLoader loader = new URLClassLoader(new URL[] { jar }, getClass().getClassLoader())) {
Class<?> config = loader.loadClass(
"org.testcontainers.shaded.com.github.dockerjava.core.DockerClientConfig"
);
Object mapper = config.getMethod("getDefaultObjectMapper").invoke(null);
Class<?> infoType = loader.loadClass("com.github.dockerjava.api.model.Info");
Object info = mapper
.getClass()
.getMethod("readValue", String.class, Class.class)
.invoke(
mapper,
"{\"ID\":\"docker-id\",\"Containers\":3,\"DockerRootDir\":\"/var/lib/docker\"}",
infoType
);

assertThat(infoType.getMethod("getId").invoke(info)).isEqualTo("docker-id");
assertThat(infoType.getMethod("getContainers").invoke(info)).isEqualTo(3);
assertThat(infoType.getMethod("getDockerRootDir").invoke(info)).isEqualTo("/var/lib/docker");
}
}

private ListAssert<String> assertThatFileList(Path path) throws IOException {
return (ListAssert) assertThat(Files.list(path))
.extracting(Path::getFileName)
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Using Gradle 5.0 or higher, you can add the following to the `dependencies` sect
But there are also "private", implementation detail dependencies (e.g., docker-java-core, Guava, OkHttp, etc.) that are not exposed to public API but prone to conflicts with test code/application under test code.
As such, **these libraries are 'shaded' into the core Testcontainers JAR** and relocated under `org.testcontainers.shaded` to prevent class conflicts.

`jackson-annotations` is a transitive dependency of `docker-java-api` and is not shaded. If you manage Jackson versions, keep this artifact compatible with the Jackson version used by Testcontainers. Forcing an older version can cause linkage errors in the shaded mapper.

## Sponsors

A huge thank you to our sponsors:
Expand Down
Loading