您可以使用 IntelliJ 原生匯入器Eclipse Buildship 在 IDE 中開啟範例。

這個範例顯示如何建立具有依賴解析結果作為輸入之任務的外掛。外掛透過包含的建置封裝,並在 Java 應用程式的多專案建置中示範。

settings.gradle.kts
includeBuild("dependency-reports")

include("utilities")
include("list")
list/build.gradle.kts
plugins {
    id("java-library")
}
utilities/build.gradle.kts
plugins {
    id("java-library")
}

dependencies {
    api(project(":list"))
}
build.gradle.kts
plugins {
    id("application")
    id("com.example.dependency-reports")
}

dependencies {
    constraints {
        implementation("org.apache.commons:commons-text:1.9")
    }
    implementation("org.apache.commons:commons-text")
    implementation(project(":utilities"))
}
settings.gradle
includeBuild "dependency-reports"

include "utilities"
include "list"
list/build.gradle
plugins {
    id "java-library"
}
utilities/build.gradle
plugins {
    id "java-library"
}

dependencies {
    api project(":list")
}
build.gradle
plugins {
    id "application"
    id "com.example.dependency-reports"
}

dependencies {
    constraints {
        implementation "org.apache.commons:commons-text:1.9"
    }
    implementation "org.apache.commons:commons-text"
    implementation project(":utilities")
}

執行範例任務

> ./gradlew -q listResolvedArtifacts
FILE commons-text-1.9.jar
  id: commons-text-1.9.jar (org.apache.commons:commons-text:1.9)
  variant: org.apache.commons:commons-text:1.9 configuration runtime
  size: 216211

FILE utilities.jar
  id: utilities.jar (project :utilities)
  variant: configuration ':utilities:runtimeElements'
  size: 261

FILE commons-lang3-3.11.jar
  id: commons-lang3-3.11.jar (org.apache.commons:commons-lang3:3.11)
  variant: org.apache.commons:commons-lang3:3.11 configuration runtime
  size: 577742

FILE list.jar
  id: list.jar (project :list)
  variant: configuration ':list:runtimeElements'
  size: 261

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
> ./gradlew -q graphResolvedComponents
project :
  org.apache.commons:commons-text -> org.apache.commons:commons-text:1.9
    org.apache.commons:commons-lang3:3.11 -> org.apache.commons:commons-lang3:3.11
  project :utilities -> project :utilities
    project :list -> project :list
  org.apache.commons:commons-text:1.9 -> org.apache.commons:commons-text:1.9 (already seen)

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
> ./gradlew -q graphResolvedComponentsAndFiles
project :
  org.apache.commons:commons-text -> org.apache.commons:commons-text:1.9 => commons-text-1.9.jar
    org.apache.commons:commons-lang3:3.11 -> org.apache.commons:commons-lang3:3.11 => commons-lang3-3.11.jar
  project :utilities -> project :utilities => utilities.jar
    project :list -> project :list => list.jar
  org.apache.commons:commons-text:1.9 -> org.apache.commons:commons-text:1.9 => commons-text-1.9.jar (already seen)

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

如需更多資訊,請參閱 撰寫任務參考章節。此外,請參閱 增量建置 章節及其 使用依賴解析結果 區段。