maven 混合編譯 java/scala 程式碼報錯(qbit)

qbit發表於2023-03-26

前言

  • 技術棧

    Windows  10
    Java/JDK 1.8.0_202
    Maven    3.6.3
    spark    2.4.6
    scala    2.12
    hadoop   2.6.0-cdh5.10.0
  • 作業系統中並沒有安裝 scala,利用 pom.xml 中的外掛編譯 scala 程式碼

報錯現象

  • 編譯命令

    mvn -D maven.test.skip=true clean scala:compile compile package
  • 報如下錯誤

    ......
    [ERROR] error: java.lang.StackOverflowError
    ......
    [INFO]  at scala.tools.nsc.javac.JavaScanners$JavaScanner.skipBlockComment(JavaScanners.scala:585)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  12.495 s
    [INFO] Finished at: 2023-03-20T13:56:52+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.4.6:compile (default-cli) on project DataAnalysis_aws_smartlib: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: -10000 (Exit value: -10000) -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解決辦法

  • 給編譯外掛新增 jvm 引數 jvmArg,新增後 scala-maven-plugin 外掛完整配置如下

    <plugin>
      <groupId>net.alchim31.maven</groupId>
      <artifactId>scala-maven-plugin</artifactId>
      <version>3.4.6</version>
      <executions>
          <execution>
              <id>scala-compile-first</id>
              <phase>process-resources</phase>
              <goals>
                  <goal>add-source</goal>
                  <goal>compile</goal>
              </goals>
          </execution>
      </executions>
      <configuration>
          <jvmArgs>
              <!-- 指定 scala 編譯時棧大小 -->
              <jvmArg>-Xss4m</jvmArg>
          </jvmArgs>
          <scalaVersion>${scala.version}</scalaVersion>
      </configuration>
    </plugin>
  • scala-maven-plugin 外掛 GitHub 地址:https://github.com/davidB/scala-maven-plugin

相關閱讀

  • JVM 引數及預設值

    -Xms
    指定jvm堆的初始大小,預設為實體記憶體的1/64,最小為1M;
    可以指定單位,比如k、m,若不指定,則預設為位元組。
    
    -Xmx
    指定jvm堆的最大值,預設為實體記憶體的1/4或者1G,最小為2M;單位與-Xms一致。
    
    -Xss
    設定單個執行緒棧的大小,一般預設為512k。
本文出自 qbit snap

相關文章