编译Spark源码

时间:2023-02-03 00:11:29

Spark编译有两种处理方式,第一种是通过SBT,第二种是通过Maven。作过Java工作的一般对于Maven工具会比较熟悉,这边也是选用Maven的方式来处理Spark源码编译工作。

在开始编译工作前应当在自己的系统中配置Maven环境

参考Linux上安装Maven方案:

编译Spark源码

http://www.runoob.com/maven/maven-setup.html

编译的对象也有两种选择,第一个是下载的Apache Spark版本,这种情况不用对Maven的默认配置进行修改即可直接编译成功;第二个是Hortonworks公司所提供的Spark,他们的编译工作使用了hortonworks公司的私人远程远程库,所以需要简单配置一下,具体参考:https://www.cnblogs.com/yuanyifei1/p/9122880.html

打开spark项目根目录下pom.xml,找到repositories节点,添加

<repository>
<id>public</id>
<url>http://nexus-private.hortonworks.com/nexus/content/groups/public</url>
</repository>

如果不配置仓库直接使用mvn -DskipTests clean package编译HDP的spark2源码,会报错找不到jar包。

编译Spark源码

在此基础上将包配置一下。

编译Spark源码

将Spark编译成功后可以通过./dev/make-distribution.sh脚本生成部署包,其中就会包含有所需的deb包。如果能够确定当前所修改的Spark源码处于那部分jar或pyspark,可以直接将其取出放在原有的deb包中,确保上线的稳定性。

将Hortonworks所提供的源码编译打包后需要对其进行安装工作。他们本身是不欢迎对源码进行修改上线的,在安装包中也是配置了GPG校验,在安装工作时需要对加密文件进行破解后安装。

踩坑

main:
[exec] fatal: 不是一个 git 仓库(或者直至挂载点 / 的任何父目录)
[exec] 停止在文件系统边界(未设置 GIT_DISCOVERY_ACROSS_FILESYSTEM)。
[exec] fatal: 不是一个 git 仓库(或者直至挂载点 / 的任何父目录)
[exec] 停止在文件系统边界(未设置 GIT_DISCOVERY_ACROSS_FILESYSTEM)。
[INFO] Executed tasks
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ spark-core_2. ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying resources
[INFO] Copying resource
[INFO] Copying resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.:compile (default-compile) @ spark-core_2. ---
[INFO] Not compiling main sources
[INFO]
[INFO] --- scala-maven-plugin:3.2.:compile (scala-compile-first) @ spark-core_2. ---
[INFO] Using zinc server for incremental compilation
[warn] Pruning sources from previous analysis, due to incompatible CompileSetup.
[info] Compiling Scala sources and Java sources to /home/zhangjie/spark-2.3./core/target/scala-2.11/classes...
[error] /home/zhangjie/spark-2.3./core/src/main/scala/org/apache/spark/api/python/PythonRunner.scala:: value getLocalProperties is not a member of org.apache.spark.TaskContextImpl
[error] val localProps = context.asInstanceOf[TaskContextImpl].getLocalProperties.asScala
[error] ^
[error] one error found
[error] Compile failed at Dec , :: PM [.814s]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Spark Project Parent POM 2.3.:
[INFO]
[INFO] Spark Project Parent POM ........................... SUCCESS [ 1.751 s]
[INFO] Spark Project Tags ................................. SUCCESS [ 9.577 s]
[INFO] Spark Project Sketch ............................... SUCCESS [ 2.242 s]
[INFO] Spark Project Local DB ............................. SUCCESS [: min]
[INFO] Spark Project Networking ........................... SUCCESS [ 16.155 s]
[INFO] Spark Project Shuffle Streaming Service ............ SUCCESS [ 2.053 s]
[INFO] Spark Project Unsafe ............................... SUCCESS [ 24.178 s]
[INFO] Spark Project Launcher ............................. SUCCESS [: min]
[INFO] Spark Project Core ................................. FAILURE [: min]
[INFO] Spark Project ML Local Library ..................... SKIPPED
[INFO] Spark Project GraphX ............................... SKIPPED
[INFO] Spark Project Streaming ............................ SKIPPED
[INFO] Spark Project Catalyst ............................. SKIPPED
[INFO] Spark Project SQL .................................. SKIPPED
[INFO] Spark Project ML Library ........................... SKIPPED
[INFO] Spark Project Tools ................................ SKIPPED
[INFO] Spark Project Hive ................................. SKIPPED
[INFO] Spark Project REPL ................................. SKIPPED
[INFO] Spark Project Assembly ............................. SKIPPED
[INFO] Spark Integration for Kafka 0.10 ................... SKIPPED
[INFO] Kafka 0.10 Source for Structured Streaming ......... SKIPPED
[INFO] Spark Project Examples ............................. SKIPPED
[INFO] Spark Integration for Kafka 0.10 Assembly .......... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: : min
[INFO] Finished at: --24T15::+:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.:compile (scala-compile-first) on project spark-core_2.: Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:3.2.:compile failed.: CompileFailed -> [Help ]
[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 ] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :spark-core_2.

原因是修改Scale源码后没有修改干净,遇见这种问题还是要将自己所修改的代码仔细review一波

同时在编译源码是注意路径中不要出现中文名,会导致编译出现卡死的情况;

参考资料:

https://www.cnblogs.com/yuanyifei1/p/9122880.html#undefined