Skip to content

[Bug]: Exception when running testcontainer from a groovy-maven-plugin script #7923

Closed as not planned
@mwrobel-mirakl

Description

@mwrobel-mirakl

Module

Core

Testcontainers version

1.19.3

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

Client: Docker Engine - Community
 Version:           23.0.3
 API version:       1.42
 Go version:        go1.19.7
 Git commit:        3e7cbfd
 Built:             Tue Apr  4 22:05:48 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.3
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.7
  Git commit:       59118bf
  Built:            Tue Apr  4 22:05:48 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

Since the upgrade to testcontainer 1.19.2+ the following exception is displayed when running testcontainer from a groovy-maven-plugin script: java.lang.ClassNotFoundException: org.testcontainers.shaded.com.github.dockerjava.core.command.KillContainerCmdImpl.

Here is a POM that can be used to reproduce the issue:

<project>
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>1</version>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>groovy-maven-plugin</artifactId>
        <version>2.1.1</version>

        <executions>
          <execution>
            <id>start-postgresql</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                new org.testcontainers.containers.PostgreSQLContainer("postgres:14-alpine")
                  .withUsername("test")
                  .withDatabaseName("test")
                  .withPassword("test")
                  .start()
              </source>
            </configuration>
          </execution>
        </executions>

        <dependencies>
          <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>postgresql</artifactId>
            <version>1.19.1</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

Prior to that version (1.19.1 or below) there was no exception.

Note that this has no consequence on the good execution of the script.

Relevant log output

$ mvn -v
Apache Maven 3.8.8 (4c87b05d9aedce574290d1acc98575ed5eb6cd39)
Maven home: /home/marc.wrobel/.asdf/installs/maven/3.8.8
Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /home/marc.wrobel/.asdf/installs/java/temurin-17.0.9+9
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.2.0-37-generic", arch: "amd64", family: "unix"

$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------------< test:test >------------------------------
[INFO] Building test 1
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- groovy-maven-plugin:2.1.1:execute (start-postgresql) @ test ---
[INFO] Image pull policy will be performed by: DefaultPullPolicy()
[INFO] Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
[INFO] Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
[INFO] Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
[INFO] Docker host IP address is localhost
[INFO] Connected to docker: 
  Server Version: 23.0.3
  API Version: 1.42
  Operating System: Ubuntu 22.04.3 LTS
  Total Memory: 31715 MB
[INFO] Creating container for image: testcontainers/ryuk:0.5.1
[INFO] Container testcontainers/ryuk:0.5.1 is starting: 3f095f91e01630b54eeb1c6d1ad900c7ba223403e351cad70256e90674a225d2
[INFO] Container testcontainers/ryuk:0.5.1 started in PT0.486840699S
[INFO] Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
[INFO] Checking the system...
[INFO] ✔︎ Docker server version should be at least 1.6.0
[INFO] Creating container for image: postgres:14-alpine
[INFO] Container postgres:14-alpine is starting: 16d35131866ba24f1156a07084b3be407271d94472ea307174f36f2bfdadd31b
[INFO] Container postgres:14-alpine started in PT1.505378691S
[INFO] Container is started (JDBC URL: jdbc:postgresql://localhost:32836/test?loggerLevel=OFF)
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /tmp/toto/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.427 s
[INFO] Finished at: 2023-12-11T11:24:17+01:00
[INFO] ------------------------------------------------------------------------
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: org/testcontainers/shaded/com/github/dockerjava/core/command/KillContainerCmdImpl
	at org.testcontainers.shaded.com.github.dockerjava.core.DockerClientImpl.killContainerCmd(DockerClientImpl.java:473)
	at com.github.dockerjava.api.DockerClientDelegate.killContainerCmd(DockerClientDelegate.java:280)
	at com.github.dockerjava.api.DockerClientDelegate.killContainerCmd(DockerClientDelegate.java:280)
	at org.testcontainers.utility.RyukResourceReaper.lambda$maybeStart$0(RyukResourceReaper.java:86)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ClassNotFoundException: org.testcontainers.shaded.com.github.dockerjava.core.command.KillContainerCmdImpl
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 5 more

Additional Information

It is probable that this is caused by : #7717.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions