maven 编译错误 org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

最近新接触scala代码的编写、编译,使用mvn编译项目时经常碰到“ExecuteException: Process exited with an error: 1 (Exit value: 1)” 。特别是在mvn clean再mvn package时,很容易出现。
另外,从错误日志上看不到具体是哪行代码编译有问题,找不到原因,很无奈。
最近一次出现该问题是从spark2.1.1中copy了spark-streaming-kafka-0-10_2.11子项目的源码,精简pom.xml之后编译,又出现这类问题,详细日志如下:

[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project yisou-spark-streaming-kafka-0-10_2.11: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project yisou-spark-streaming-kafka-0-10_2.11: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at scala_maven.ScalaMojoSupport.execute(ScalaMojoSupport.java:490)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
… 20 more

走了许多弯路之后(如修改scala版本号、更换maven-scala-plugin、完全复制源码的pom等),最后意外发现pom中去掉
guava的exclusion就没问题了。
会报错的pom:

       <dependency>
           <groupId>org.apache.spark</groupId>
           <artifactId>spark-core_${scala.binary.version}</artifactId>
           <version>2.1.1</version>
           <type>test-jar</type>
           <scope>provided</scope>
           <exclusions>
               <exclusion>
                   <artifactId>guava</artifactId>
                   <groupId>com.google.guava</groupId>
               </exclusion> 
           </exclusions>
       </dependency>

能正常运行的pom:

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.binary.version}</artifactId>
            <version>2.1.1</version>
            <type>test-jar</type>
            <scope>provided</scope> 
        </dependency>

为什么加了exclusion guava就编译报错了呢,如果是exclusion 其他的artifactId并没有此问题。spark-streaming-kafka-0-10_2.11源码中并没有使用guava的类。

我也暂时没查出原因,在此提醒遇到类似问题的朋友,多从pom配置而不是代码入手,特别注意guava的exclusion很可能会造成此问题。

    原文作者:westfire
    原文地址: https://www.jianshu.com/p/2fe0a0b8f14a
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞