一、Spark 2.4.0 源碼編譯

1.環境準備

  1. JAVA
    java的話,直接安裝個1.8就行了,配置好環境變量和JAVA_HOME,在cmd當中java一下,確認java安裝好即可。

  2. scala
    scala安裝和java類似,把Scala安裝包解壓,然後配置好Windows環境變量中的path當中還有SCALA_HOME,這裏根據你想要閱讀的源碼,選擇合適的scala版本,我用的是scala 2.11版本,然後scala -version一下,確認安裝好了。

  3. maven
    maven 安裝也是一樣的,配置好MAVEN_HOME還有path即可。我安裝的版本是3.6.1,推薦你們使用比較新的maven版本

  4. IDEA
    這個根據個人選擇選擇合適的開發工具,如果選擇了idea,記得選擇File->setting->plugins 然後搜索scala,安裝scala插件。

  5. git
    安裝git是爲了拉源碼進行編譯和源碼閱讀,直接從官網下安裝即可。

  6. spark源碼
    spark源碼我選擇的是2.4版本,這裏有個需要注意的問題是如果你直接從git上拉代碼,可能超級慢,這裏推薦個方法,就是註冊個碼雲(https://gitee.com/),然後註冊好進去後,然後點右上角加號,有個
    在這裏插入圖片描述然後新建倉庫
    在這裏插入圖片描述然後導入https://github.com/apache/spark.git 這個spark git上的地址,你就在碼雲上有了自己的倉庫,然後從碼雲去clone代碼,就會快得多。
    在這裏插入圖片描述

2.編譯代碼

mvn -Pyarn -Phadoop2.7.4 -Pkinesis-asl -Phive -DskipTests clean package

進行編譯的時候,可能會有這麼以下幾個問題:
一、
下載某個依賴或者插件超時,顯示timeout,這時可能是網絡的問題(pom裏指定默認倉庫還像是谷歌,根本連不上。。。)
打開spark source裏面spark-parent的pom文件(就是·父目錄的pom),修改如下內容:

<repositories>
    <repository>
      <!--
        This is used as a fallback when the first try fails.
      -->
      <id>central</id>
      <name>Maven Repository</name>
      <!--      <url>https://repo.maven.apache.org/maven2</url>-->
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
<!--    <repository>-->
<!--      <id>gcs-maven-central-mirror</id>-->
<!--      &lt;!&ndash;-->
<!--        Google Mirror of Maven Central, placed first so that it's used instead of flaky Maven Central.-->
<!--        See https://storage-download.googleapis.com/maven-central/index.html-->
<!--      &ndash;&gt;-->
<!--      <name>GCS Maven Central mirror</name>-->
<!--      <url>https://maven-central.storage-download.googleapis.com/maven2/</url>-->
<!--      <releases>-->
<!--        <enabled>true</enabled>-->
<!--      </releases>-->
<!--      <snapshots>-->
<!--        <enabled>false</enabled>-->
<!--      </snapshots>-->
<!--    </repository>-->
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <!--      <url>https://repo.maven.apache.org/maven2</url>-->
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
<!--    <pluginRepository>-->
<!--      <id>gcs-maven-central-mirror</id>-->
<!--      &lt;!&ndash;-->
<!--        Google Mirror of Maven Central, placed first so that it's used instead of flaky Maven Central.-->
<!--        See https://storage-download.googleapis.com/maven-central/index.html-->
<!--      &ndash;&gt;-->
<!--      <name>GCS Maven Central mirror</name>-->
<!--      <url>https://maven-central.storage-download.googleapis.com/maven2/</url>-->
<!--      <releases>-->
<!--        <enabled>true</enabled>-->
<!--      </releases>-->
<!--      <snapshots>-->
<!--        <enabled>false</enabled>-->
<!--      </snapshots>-->
<!--    </pluginRepository>-->
  </pluginRepositories>

將倉庫改爲國內地址,因爲pom默認指定的是谷歌倉庫地址,而且第二默認的maven倉庫地址感覺也不好用,所以這裏要改一下。

二、
Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed
這時因爲spark中用插件對java版本和maven版本進行了規約。
在這裏插入圖片描述 在這裏插入圖片描述因爲我本地安裝的maven版本是3.6.1,所以有兩種方法:
1.要麼安裝3.6.3的manven版本
2.將圖中的參數改爲3.6.1

如果你覺得maven版本和spark當中規約的版本相差不大(別差一個大版本那種),可以更改圖中參數。

在這裏插入圖片描述
在這裏插入圖片描述
三、中途如果有多次中斷或者卡死,內存溢出啥的,直接殺掉從新編譯即可

經過上述問題,即可順利編譯spark源碼啦。

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章