LoginSignup
6
2

More than 1 year has passed since last update.

【自分用メモ】Mavenのスコープについて

Last updated at Posted at 2021-09-25

参考

やはり英語ドキュメントの方が分かりやすかった。
https://howtodoinjava.com/maven/maven-dependency-scopes


スコープとは

Maven dependency scope attribute is used to specify the visibility of a dependency, relative to the different lifecycle phases (build, test, runtime etc). Maven provides six scopes i.e. compile, provided, runtime, test, system, and import.

「visibility of a dependency(依存性の可視性)」を設定するための属性。

もうちょい砕くと

「JUnitはテスト実行時のみ使える(見える)ようにしよう」
「DBドライバはアプリ実行時のみ使える(見える)ようにしよう」

みたいな感じ。


「〜」の時にはこの依存性が使える(見える)ようにしよう。どんな時?

タイミング 何してるの
① build ビルド(実行可能なファイルを作成する)時
② test テスト実行時
③ run アプリ実行時

6つのスコープ

①build ②test ③run 具体例(ライブラリ)
compile (デフォ)
provided
(実行環境から与えられるから実行時には見えなくていい)
✖︎ ・lombok
・maven-plugin-annotations
runtime
(アプリ実行時にしか使わないから実行時に見えるように)
✖️ ・postgres(DBドライバ)
・spring-boot-devtools(ソース修正→HotReload)
test
(テスト実行時にしか使わないからテスト実行時のみ見えるように)
✖️ ✖️ ・spring-test
・spring-security-test
・spring-boot-starter-test
・awaitility
・junit
・junit-jupiter-api
・mockito
・selenide
・maven-plugin-testing-harness
system
(providedの「実行環境から与えられないバージョン」)
✖️ ・MavenリモートリポジトリにはないJARファイル等
importスコープ

・dependencyManagement要素内で定義する依存性
・transitive dependencyの定義をするためのスコープ
・具体例
 - spring-boot-dependencies(springのバージョン指定)
 - software.amazon.awssdk(AWS SDKのバージョン指定)

6
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2