现象

执行 mvn clean package -DskipTestsORC 打包失败,报错如下:

[INFO] Resolving artifact: com.google.protobuf:protoc:2.5.0, platform: osx-aarch_64
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Apache ORC 1.5.8:
[INFO]
[INFO] Apache ORC ......................................... SUCCESS [  0.844 s]
[INFO] ORC Shims .......................................... SUCCESS [  1.040 s]
[INFO] ORC Core ........................................... FAILURE [  0.046 s]
[INFO] ORC MapReduce ...................................... SKIPPED
[INFO] ORC Tools .......................................... SKIPPED
[INFO] ORC Examples ....................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.003 s
[INFO] Finished at: 2022-02-23T14:59:43+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.5.1.1:run (default) on project orc-core: Error resolving artifact: com.google.protobuf:protoc:2.5.0: Could not transfer artifact com.google.protobuf:protoc:exe:osx-aarch_64:2.5.0 from/to maven-default-http-blocker XXXXX
[ERROR]   com.google.protobuf:protoc:exe:2.5.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR]  XXX
[ERROR] -> [Help 1]
[ERROR]

分析

从报错即可看出,打包时由于系统为 osx-aarch_64 架构,所以会去找 protoc-2.5.0-osx-aarch_64 名字样式的包,查看 nexus 仓库,没有这种名字的包:
image-1658040200258
修改思路当然是将 protoc-2.5.0-osx-aarch_64.exe 替换为 protoc-2.5.0-osx-x86_64.exe。查看文档知系统架构通过 os.arch 指定即可,于是执行 mvn clean package -DskipTests -Dos.arch=x86_64,打包成功。

查了下github上的解决方案,若 pom.xml 文件中使用的插件能设置 protoc 的 os arch 类型

<protocArtifact>com.google.protobuf:protoc:3.14.0:exe:${os.detected.classifier}</protocArtifact>

也可以直接修改该 os arch

<protocArtifact>com.google.protobuf:protoc:3.14.0:exe:osx-x86_64</protocArtifact>

或修改 ./m2/settings.xml 文件:

<settings>
  ...
  <activeProfiles>
    <activeProfile>
      apple-silicon
    </activeProfile>
    ...
  </activeProfiles>
  <profiles>
    <profile>
      <id>apple-silicon</id>
      <properties>
        <os.detected.classifier>osx-x86_64</os.detected.classifier>
      </properties>
    </profile>
    ...
  </profiles>
  ...
</settings>

如果没有本地安装maven,也可以直接在IDEA中直接配置maven执行参数,
Preferences -> Build,Execution,Deployment -> Build Tools -> maven -> Runner -> VM Options
中填入 -Dos.arch=x86_64 指定maven运行时获取到的芯片名。

Mac M1 芯片编译 protoc 报错