Scala 3

Scala 3 setup

Jacob Xie published on
2 min, 214 words

Categories: Doc

Tags: Scala

Scala 3

  • JDK 11

    sudo apt-get install openjdk-11-jdk
    

    make sure $JAVA_HOME is set in ~/.bashrc:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    
  • SBT

    echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
    echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
    curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
    sudo apt-get update
    sudo apt-get install sbt
    
  • (Optional) Set sbt mirror

    create repositories (huawei mirror) under ~/.sbt/:

    [repositories]
    local
    huaweicloud-maven: https://repo.huaweicloud.com/repository/maven/
    maven-central: https://repo1.maven.org/maven2/
    sbt-plugin-repo: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
    
  • (Optional) Set global repo for all projects (rather than each project holds its own repo)

    cd /etc/sbt
    

    then sudo vim sbtopts add one line at the bottom:

    -Dsbt.override.build.repos=true
    
  • Check everything, first by executing sbt and enter to sbt shell

    check sbt version:

    sbtVersion
    

    check global repo if override:

    show overrideBuildResolvers
    

    show resolvers:

    show fullResolvers
    
  • Create a new scala3 project

    sbt new scala/scala3.g8
    
  • (Optional) vs-code extension Metals, again please make sure that $JAVA_HOME is set.