Closed3

Gradle docs Reading

301 Moved Permanently301 Moved Permanently

Learning the Basics

Setting File Basics

Add subprojects

サブプロジェクトを追加するにはsettings.gradle.ktsに以下のように記述する。

include("sub-project-a")
include("sub-project-b")
include("sub-project-c")

Dependencies Basics

Declaring Your Dependencies

依存関係の種類は複数ある。
testImplementation, runtimeOnly, compileOnly, api, and more.
これはAnthonyの考えと同じ。
https://antfu.me/posts/categorize-deps

Incremental Builds and Build Caching Basic

Incremental builds

Gradleでは増分ビルドが常に有効になっている。変更のあるなしはverboseモードでコマンドを実行することでわかる。

./gradlew compileJava --console=verbose

このモードを永続的に有効にするには、gradle.propertiesorg.gradle.console=verboseを追加する。

Build caching

増分ビルドが使えたとしても、先週で更新が止まっているブランチにチェックアウトした場合はキャッシュが効かなくなる。そこで便利なのがこれ。

./gradlew compileJava --build-cache

Define Version Catalog

gradle/libs.versions.tomlにバージョンカタログを記載できる。

[versions]
guava = "33.3.1-jre"
junit-jupiter = "5.11.3"

[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }

こう書ける。

app/build.gradle.kts
dependencies {  
    // Use JUnit Jupiter for testing.
    testImplementation(libs.junit.jupiter)

    testRuntimeOnly("org.junit.platform:junit-platform-launcher")

    // This dependency is used by the application.
    implementation(libs.guava)
}
このスクラップは4ヶ月前にクローズされました