localstack / localstack-java-utils

☕ Java utilities and JUnit integration for LocalStack
Apache License 2.0
75 stars 43 forks source link

Using localstack-java-utils together with Testcontainers throws UnsatisfiedLinkError #97

Open rkhlebnov opened 1 year ago

rkhlebnov commented 1 year ago

Problem occurred while developing on Mac with M1 chip.

Maven pom.xml dependency sample to reproduce the problem:

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <version>1.17.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>1.17.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>cloud.localstack</groupId>
            <artifactId>localstack-utils</artifactId>
            <version>0.2.21</version>
            <scope>test</scope>
        </dependency>

During tests, following error pops up:

java.lang.UnsatisfiedLinkError: Can't load library: /var/folders/8h/c61frhdx4h755wk7dbgny_w80000gn/T/jna--1389878725/jna11007918705638209843.tmp

After investigating dependencies tree, I've discovered that JNA dependency of this library overrides JNA version of Testcontainers:

[INFO] +- org.testcontainers:testcontainers:jar:1.17.6:test
[INFO] |  +- junit:junit:jar:4.13.2:test
[INFO] |  |  \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] |  +- org.apache.commons:commons-compress:jar:1.22:test
[INFO] |  +- org.rnorth.duct-tape:duct-tape:jar:1.0.8:test
[INFO] |  |  \- org.jetbrains:annotations:jar:17.0.0:compile
[INFO] |  +- com.github.docker-java:docker-java-api:jar:3.2.13:test
[INFO] |  \- com.github.docker-java:docker-java-transport-zerodep:jar:3.2.13:test
[INFO] |     \- com.github.docker-java:docker-java-transport:jar:3.2.13:test
[INFO] +- org.testcontainers:junit-jupiter:jar:1.17.6:test
[INFO] |  \- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
[INFO] |     +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |     +- org.junit.platform:junit-platform-commons:jar:1.8.2:test
[INFO] |     \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] \- cloud.localstack:localstack-utils:jar:0.2.21:test
[INFO]    +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO]    +- net.java.dev.jna:jna:jar:4.1.0:test

Solution that helped:

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <version>1.17.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>1.17.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>cloud.localstack</groupId>
            <artifactId>localstack-utils</artifactId>
            <version>0.2.21</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>net.java.dev.jna</groupId>
                    <artifactId>jna</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

with resulting dependency tree:

[INFO] +- org.testcontainers:testcontainers:jar:1.17.6:test
[INFO] |  +- junit:junit:jar:4.13.2:test
[INFO] |  |  \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] |  +- org.apache.commons:commons-compress:jar:1.22:test
[INFO] |  +- org.rnorth.duct-tape:duct-tape:jar:1.0.8:test
[INFO] |  |  \- org.jetbrains:annotations:jar:17.0.0:compile
[INFO] |  +- com.github.docker-java:docker-java-api:jar:3.2.13:test
[INFO] |  \- com.github.docker-java:docker-java-transport-zerodep:jar:3.2.13:test
[INFO] |     +- com.github.docker-java:docker-java-transport:jar:3.2.13:test
[INFO] |     \- net.java.dev.jna:jna:jar:5.8.0:test
[INFO] +- org.testcontainers:junit-jupiter:jar:1.17.6:test
[INFO] |  \- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
[INFO] |     +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |     +- org.junit.platform:junit-platform-commons:jar:1.8.2:test
[INFO] |     \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] \- cloud.localstack:localstack-utils:jar:0.2.21:test

Question: is it possible to update JNA to version to 5.8.0?