实现具有依赖关系解析结果输入的任务示例
版本 8.7
您可以使用 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