Module
Core
Testcontainers version
2.0.2
Using the latest Testcontainers version?
Yes
Host OS
MacOS Tahoe 26.1
Host Arch
ARM
Docker version
Docker Desktop for Mac: 4.54.0 (212467)
Engine: 29.1.2
What happened?
Below fails with the error as described in the log. I can't easily fix this using forced dependencies given it's using a shaded import, I'm using Gradle.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.MountableFile;
@Testcontainers
class PostgresIntegrationTest {
@Container
private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("testdb")
.withUsername("testuser")
.withPassword("testpass")
.withInitScript("sql/init.sql")
// .withCopyFileToContainer(
// MountableFile.forClasspathResource("sql"),
// "/docker-entrypoint-initdb.d"
// )
;
@Test
void testDatabaseConnection() throws Exception {
// given
String jdbcUrl = postgres.getJdbcUrl();
String username = postgres.getUsername();
String password = postgres.getPassword();
// when
try (Connection conn = DriverManager.getConnection(jdbcUrl, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) {
// then
assertTrue(rs.next());
int result = rs.getInt(1);
assertEquals(1, result);
}
}
}
Relevant log output
org/testcontainers/shaded/org/apache/commons/io/IOUtils
java.lang.NoClassDefFoundError: org/testcontainers/shaded/org/apache/commons/io/IOUtils
at org.testcontainers.ext.ScriptUtils.runInitScript(ScriptUtils.java:212)
at org.testcontainers.containers.JdbcDatabaseContainer.lambda$runInitScriptIfRequired$0(JdbcDatabaseContainer.java:368)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.testcontainers.containers.JdbcDatabaseContainer.runInitScriptIfRequired(JdbcDatabaseContainer.java:368)
at org.testcontainers.containers.JdbcDatabaseContainer.containerIsStarted(JdbcDatabaseContainer.java:221)
at org.testcontainers.containers.GenericContainer.containerIsStarted(GenericContainer.java:716)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:529)
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
Additional Information
No response
Module
Core
Testcontainers version
2.0.2
Using the latest Testcontainers version?
Yes
Host OS
MacOS Tahoe 26.1
Host Arch
ARM
Docker version
Docker Desktop for Mac: 4.54.0 (212467) Engine: 29.1.2What happened?
Below fails with the error as described in the log. I can't easily fix this using forced dependencies given it's using a shaded import, I'm using Gradle.
Relevant log output
Additional Information
No response