testcontainers-java: Fails on m1 mac docker preview, java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native

https://www.docker.com/blog/download-and-try-the-tech-preview-of-docker-desktop-for-m1/

(possibly wrong repo to report this to)

UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native). Root cause NoClassDefFoundError (Could not initialize class com.sun.jna.Native)

   1.490 [id=16]	WARNING	o.t.u.TestcontainersConfiguration#readProperties: Attempted to read Testcontainers configuration file at file:/Users/timja/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /Users/timja/.testcontainers.properties (No such file or directory)
   1.496 [id=16]	INFO	o.t.d.DockerMachineClientProviderStrategy#isApplicable: docker-machine executable was not found on PATH ([/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin, /Users/timja/bin, /usr/local/bin, /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin, /Users/timja/code/jenkins/backend-commit-history-parser/bin])
   1.675 [id=16]	SEVERE	o.t.d.DockerClientProviderStrategy#lambda$getFirstValidStrategy$7: Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
   1.675 [id=16]	SEVERE	o.t.d.DockerClientProviderStrategy#lambda$getFirstValidStrategy$7:     UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native). Root cause NoClassDefFoundError (Could not initialize class com.sun.jna.Native)
   1.675 [id=16]	SEVERE	o.t.d.DockerClientProviderStrategy#lambda$getFirstValidStrategy$7: As no valid configuration was found, execution cannot continue

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

3.2.7 depends on JNA 5.5.0 (not compatible with M1), 3.2.8 on 5.8.0 (compatible).

Also, we just released Testcontainers 1.15.3 and it depends on JNA 5.8.0 ๐ŸŽ‰

@bsideup released version 1.15.3 still depends on

 <dependency>
      <groupId>org.rnorth.visible-assertions</groupId>
      <artifactId>visible-assertions</artifactId>
      <version>2.1.2</version>
      <scope>compile</scope>
    </dependency>

which depends on jna 5.2.0 which causes (for me locally) to only pull 5.2.0 and skip 5.8.0 ๐Ÿ˜ฆ

... from org.rnorth.visible-assertions ...
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.2.0</version>
        </dependency>

I 've added manual dependency to 5.8.0 and it worked only after that ๐Ÿ˜ƒ no worries but it could help to @todor-kolev

        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.8.0</version>
        </dependency>

I should be checking updates more often indeed )) thnx

@todor-kolev soon, but you donโ€™t have to wait for it to be released, just add JNA 5.8.0 to your dependencies list (as @pie-ai did). Also, docker-java 3.2.8 is already released and depends on 5.8.0, you can update the docker-java dependency as an alternative

The root cause is JNA and its lacking M1 support - consider reporting to them. Also, I was able to run it with Rosetta (since my IDEA is running with Rosetta already)

FYI even tho the โ€œcoreโ€ functionality of Testcontainers works (Ryuk, alpine checks, connectivity), some modules (like Kafka) are failing. I hope future versions of Docker Desktop preview would fix it.

Thanks docker-java 3.2.8 worked for me on M1 to detect docker from test-containers (Docker Desktop RC 3). Version 3.2.7 did not detect docker.

        <dependency>
            <groupId>com.github.docker-java</groupId>
            <artifactId>docker-java-api</artifactId>
            <version>3.2.8</version>
        </dependency>
        <dependency>
            <groupId>com.github.docker-java</groupId>
            <artifactId>docker-java-transport-zerodep</artifactId>
            <version>3.2.8</version>
        </dependency>