SBT--入门并在IDEA中使用

SBT简介

  SBT(Simple Build Tool),对于SBT官网是这样介绍的”The interactive build tool,Use Scala to define your tasks. Then run them in parallel from the shell.“。即是一个现代构建工具,它是用Scala编写的,对编译Scala、Spark项目提供了不错的支持。和Maven一样它也是一个通用的构建工具。

SBT安装

  1. 配置环境变量
    SBT_HOME=D:\dev\sbt
    %SBT_HOME%\bin;

  2. 修改配置文件sbtconfig.txt

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    # Set the java args to high

    -Xmx512M

    -XX:MaxPermSize=256m

    -XX:ReservedCodeCacheSize=128m

    # Set the extra SBT options
    -Dactivator.checkForUpdates=false
    -Dsbt.log.format=true
    -Dhttp.proxyHost=proxy.tencent.com
    -Dhttp.proxyPort=8080
    -Dhttps.proxyHost=proxy.tencent.com
    -Dhttps.proxyPort=8080

    # 设置boot目录以及ivy本地仓库地址
    -Dsbt.boot.directory=D:/dev/sbt/boot/
    -Dsbt.ivy.home=D:/dev/sbt/ivy2/
    -Dsbt.repository.config=D:/dev/sbt/conf/repo.properties
  3. conf目录下创建repo.properties文件,内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [repositories]

    local

    ui:http://uk.maven.org/maven2/
    ui-ivy:http://uk.maven.org/maven2/,[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

    typesafe:http://repo.typesafe.com/typesafe/releases/
    typesafe-ivy: http://repo.typesafe.com/typesafe/ivy-releases/,[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
    sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/
    sonatype: http://oss.sonatype.org/content/repositories/snapshots
    repo2: http://repo2.maven.org/maven2/

SBT运行

在IDEA中使用

  1. 安装:idea 安装配置SBT,点击install安装后重启IDEA

  2. 配置idea:如果不配置,SBT_HOME下面的配置是对idea无效的,有两种方式

  • 第一种:解压sbt-launch.jar,修改里面的sbt.boot.properties文件,在repositories配置项中添加镜像配置重新打包(这里就不做具体说明)
  • 第二种:
    2.1. 在idea配置

    2.2. 在用户目录下的.sbt文件夹下,创建一个repositories文件,文件内容为镜像文件repo.properties的内容。

创建SBT项目

创建SBT项目
可以看见在通过我们自定义的仓库下载依赖
项目整体结构

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器