SBT 프로젝트 설정과 기초
새 SBT 프로젝트를 초기화하고 설정을 정의하며 일반적인 빌드 작업을 실행하는 방법을 배웁니다.
SBT 프로젝트 설정과 기초은(는) CoddyKit의 무료 Scala for Backend Engineering & Functional Programming 강의입니다. 이것은 3개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Scala for Backend Engineering & Functional Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Scala for Backend Engineering & Functional Programming 강의에는 총 3개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Welcome to SBT!
Hello! Today we're diving into SBT, the standard build tool for Scala projects. Think of it as your project's manager, handling everything from compiling code to running tests and packaging your application.
SBT stands for Scala Build Tool. It simplifies complex tasks and ensures your projects are set up correctly.
Why Use SBT?
SBT brings several benefits to Scala development:
- Dependency Management: Easily add external libraries your project needs.
- Project Structure: Enforces a standard layout, making projects easy to navigate.
- Task Automation: Automate compilation, testing, packaging, and more with simple commands.
- Consistency: Ensures everyone on a team builds and runs the project in the same way.
Getting SBT Installed
Before we can use SBT, we need to install it. The recommended way is often through a package manager like Coursier or Homebrew (on macOS/Linux) or by downloading the official launcher.
Once installed, you can verify it by checking the version in your terminal:
sbt --versionCreating a New Project
SBT provides a convenient way to create new projects using templates. We'll use the sbt new command with a basic Scala seed template.
This command will set up the necessary directories and files for a simple Scala application:
sbt new scala/scala-seed.g8 --name my-first-sbt-appExploring Project Structure
After creating my-first-sbt-app, you'll see a standard directory structure:
src/main/scala/: Your main Scala source code goes here.src/test/scala/: For your test files.project/: Contains project-specific SBT configurations.build.sbt: The main configuration file for your project.
The build.sbt file is where you define project settings.
Basic build.sbt Configuration
The build.sbt file uses a simple syntax to define project settings. Here's a basic example:
name := "my-first-sbt-app": Sets your project's name.version := "0.1.0-SNAPSHOT": Defines the project's version.scalaVersion := "2.13.12": Specifies the Scala version to use.
These are key-value pairs where := assigns a value to a setting.
name := "my-first-sbt-app"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.13.12"Your First Scala Program
Let's add a simple Scala program to our project. Inside src/main/scala/, create a file named Main.scala. This program will just print a greeting.
SBT will automatically find and compile this file when you run commands like compile or run.
object Main {
def main(args: Array[String]): Unit = {
println("Hello from SBT!")
}
}Running Your Application
With your Main.scala file in place, navigate to your project's root directory in the terminal (e.g., cd my-first-sbt-app).
You can then use the sbt run command. SBT will compile your code and execute the main method it finds.
sbt runThe SBT Interactive Shell
You can also enter the SBT interactive shell by just typing sbt in your project's root directory. This keeps SBT running, making subsequent commands faster.
Inside the shell, you can type commands like compile, run, or test directly. Type exit to leave the shell.
sbt
> compile
> run
> exitQuick Check: SBT Basics
Which of the following settings is typically used in build.sbt to specify the Scala version for your project?
SBT Journey Continues!
Great job! You've taken your first steps with SBT.
We covered:
- What SBT is and why it's essential.
- How to set up a new SBT project.
- Understanding the basic project structure.
- Configuring fundamental settings in
build.sbt. - Running your first Scala application using SBT commands.
Next, we'll explore how to manage external libraries and use SBT plugins to extend your project's capabilities!
자주 묻는 질문
“SBT 프로젝트 설정과 기초” 강의는 무료인가요?
네 — “SBT 프로젝트 설정과 기초” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Scala for Backend Engineering & Functional Programming 강의 전체를 잠금 해제할 수 있습니다. Scala for Backend Engineering & Functional Programming 강의에는 총 3개의 강의가 포함되어 있습니다.
“SBT 프로젝트 설정과 기초”에서 뭘 배우나요?
새 SBT 프로젝트를 초기화하고 설정을 정의하며 일반적인 빌드 작업을 실행하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Scala for Backend Engineering & Functional Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Scala for Backend Engineering & Functional Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Scala for Backend Engineering & Functional Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 3개 중 1번째 강의입니다.
“SBT 프로젝트 설정과 기초” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Scala for Backend Engineering & Functional Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Scala for Backend Engineering & Functional Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- SBT 프로젝트 설정과 기초
- 의존성 관리와 플러그인
- 다중 프로젝트 빌드와 배포