Maven リポジトリ
Maven リポジトリで公開されているライブラリへの依存は以下のように定義します。
dependencies: - org.apache.commons:commons-lang3:3.20.0 - org.apache.commons:commons-collections4:4.5.0
BOMの場合は以下のように定義でき、バージョン番号の定義が省略できるようになります。
dependencies: - bom: io.ktor:ktor-bom:2.2.0 - io.ktor:ktor-client-core
デフォルトのリポジトリとして以下が設定されています。
| Name | URL |
|---|---|
| Maven Central | https://repo1.maven.org/maven2 |
| https://maven.google.com |
デフォルト以外のリポジトリを設定する場合は以下のように指定することができます。
repositories: - https://repo.spring.io/ui/native/release
id を指定して以下のように定義することもできます。
repositories: - id: spring url: https://repo.spring.io/ui/native/release
依存スコープ
依存スコープを指定する場合は、compile-only と runtime-only を指定できます。
dependencies: - org.apache.commons:commons-lang3:3.20.0: compile-only - org.apache.commons:commons-collections4:4.5.0: runtime-only
何も指定しない場合は all となり、これがデフォルトとなります。
| Scope | Compilation | Runtime |
|---|---|---|
| all (default) | 〇 | 〇 |
| compile-only | 〇 | |
| runtime-only | 〇 |
Gradle の api のように依存関係を外部にも提供する場合は exported を指定します。
dependencies: - org.apache.commons:commons-lang3:3.20.0: exported
スコープ指定と exported を同時に指定する場合は以下の形式で書きます。
dependencies: - org.apache.commons:commons-lang3:3.20.0: exported: true scope: compile-only
モジュール依存関係
マルチモジュール構成の場合に、他のモジュールへの依存を定義する場合は、以下のように記載します。
dependencies: - //my-other-module
// で始るプロジェクトのルートディレクトリ(project.yaml がある場所)からの相対パスとして定義します。
../my-sibling-module のような相対パスの記法もサポートされていますが、推奨されていません。
プロジェクト・カタログ
Gradle のバージョンカタログと同様のバージョン定義ができます。
プロジェクトルートに libs.versions.toml を配置します。
[versions] ktor = "3.3.2" [libraries] ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" } ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } ktor-client-contentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
依存の定義では、$libs で参照して、以下のように記載できます。
dependencies: - $libs.ktor.client.auth - $libs.ktor.client.cio - $libs.ktor.client.contentNegotiation
Gradle からの移行用に gradle/libs.versions.toml への配備もサポートされています(双方に配備することはできません)。