Spark源码打包编译的过程

前言

上篇文章介绍了下 安装sbt环境 启动scala项目

安装SBT环境运行Scala项目

为什么要弄这个 因为我本来是想对spark源码编译部署

spark是用scala语言编译的

spark源码

https://gitee.com/pingfanrenbiji/spark

spark提供的编译方式

编译的前提是将所有的依赖包都下载下来

而资源包管理方式有maven、graddle、sbt等

maven方式

将maven资源库修改为阿里云资源库

配置方式
方式1
方式2
<repositories>
    <repository>
        <id>aliyun</id>
        <url>https://maven.aliyun.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
  • 如果你只是配置了repositories,那么你会发现在mvn在下载依赖的时候,一部分从阿里云下载,一部分还是从默认的仓库(https://repo.maven.apache.org )下载

  • 只有项目本身的依赖,走了aliyun这个repository,maven命令需要的插件(比如clean、install都是maven的插件),走的还是默认的repository

方式3

在maven setting文件中

 <mirrors>
  <mirror>  
   <id>nexus-aliyun</id>  
   <mirrorOf>central</mirrorOf>    
   <name>Nexus aliyun</name>  
   <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
  </mirror>
 </mirrors>
maven编译打包
mvn -DskipTests clean package

sbt方式

这样下载依赖包的速度超级慢

原因是从https://repo1.maven.org/maven2/这个国外的资源库网站下载的

那么类似于maven 准备换成国内的资源库

国内资源库配置方法

上面文章介绍的是配置的华为的国内资源库

这里配置下阿里的国内资源库

vim ~/.sbt/repositories

[repositories]
aliyun-maven-repo: https://maven.aliyun.com/repository/public
aliyun-nexus: https://maven.aliyun.com/nexus/content/groups/public/
typesafe: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
maven-central
sonatype-oss-releases
sonatype-oss-snapshots
ivy-sbt-plugin: https://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

检验配置的国内资源库是否生效
mkdir test
cd test
sbt
show fullResolvers

可以看到 配置的阿里云资源库 已经生效了

既然sbt资源库下载已经换成了国内的资源库了

那么试试吧

咦!怎么还是repo1.maven.org

接下来说一下 我努力挣扎的过程 反正结果以失败而告终 最后先放弃 😂

去掉sbt默认从repo1.maven.org下载的配置

第一次尝试

我是用的=直接将默认的resolvers直接替换掉

而不是用+= 默认加新增的这个

但实际效果不行

第二次尝试

我直接在spark源码中全局搜索 repo1.maven.org 没有找到

那么我就想:通过sbt 下载资源库 那么应该在sbt源码中配置的

目的:下载sbt源码 把所有的repo1.maven.org换成阿里云https://maven.aliyun.com/repository/public 然后重新打包

下载sbt源码
https://gitee.com/pingfanrenbiji/sbt.git

替换repo1.maven.org

执行打包
mkdir sbt-modules
cd sbt-modules

for i in sbt io librarymanagement zinc; do \
     git clone https://gitee.com/pingfanrenbiji/$i.git && (cd $i; git checkout -b develop origin/develop)
   done
   
cd sbt
./sbt-allsources.sh

这个脚本的内容

需要sbt命令

我瞬间凌乱了(因为我的无知)

心理活动:我的目的是下载sbt源码 然后打包生成可执行文件 sbt

但现在我打包 却需要sbt这个可执行文件。

我知道 我暂时搞不清楚这个问题的原因了 所以先准备下sbt环境 执行这个脚本 看看结果如何吧

  • sbt环境

a、上篇文章也介绍了一种方式 就是直接下载sbt资源包 然后配置环境变量

b、这里用另外一种方法

 brew install sbt
 
==> Downloading https://github.com/sbt/sbt/releases/download/v1.3.13/sbt-1.3.13.
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################## 100.0%
==> Caveats
You can use $SBT_OPTS to pass additional JVM options to sbt.
Project specific options should be placed in .sbtopts in the root of your project.
Global settings should be placed in /usr/local/etc/sbtopts
==> Summary
🍺  /usr/local/Cellar/sbt/1.3.13: 9 files, 1.4MB, built in 2 seconds

有了sbt环境 再执行sbt-allsources.sh这个脚本

瞬间吐血~(怎么还是这个资源库 我不是已经通过修改源码的方式去掉了嘛)

暂时先放弃 因为这块工作上没有要求 是我自己想学习scala研究的

后记

  • 进入一个未知的领域 在有老师指导的情况下 肯定会事半功倍 但往往都没有老师来指导 那只能靠自学

  • 自学虽然会磕磕绊绊 遇到很多挫折但学会了之后 你就会破茧成蝶

朋友们 共勉吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值