前言

  • 技术栈

    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

qbit
268 声望279 粉丝