Java on Apple M1 Mac

How to fix problems which might occur when running Java and Spring Boot on a Mac with Apple M1 processor.

Problem 1

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.

How to fix

Add build extension os-maven-plugin to generate os.detected.classifier

<build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.7.0</version>
      </extension>
    </extensions>
</build>

Add dependency netty-resolver-dns-native-macos

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-resolver-dns-native-macos</artifactId>
    <version>4.1.75.Final</version>
    <classifier>${os.detected.classifier}</classifier>
</dependency>

Or using profiles is probably better:

<profiles>
  <profile>
    <id>AppleM1</id>
    <activation>
      <os>
        <family>mac</family>
        <arch>aarch64</arch>
      </os>
    </activation>
    <dependencies>
      <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-resolver-dns-native-macos</artifactId>
        <version>4.1.75.Final</version>
        <classifier>osx-aarch_64</classifier>
      </dependency>
    </dependencies>
  </profile>
</profiles>

Problem 2

Tests might fail because

java.lang.IllegalStateException: No Server ALPNProcessors!
java.lang.UnsatisfiedLinkError: no conscrypt_openjdk_jni-osx-aarch_64

When using Wiremock.

How to fix

Set wiremock property in application.yml

wiremock:
  server:
    httpsPort: -1
Docker  Mac