From 1494deb4a03b7fde47d43deb0b5ce7b52259f3ae Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 15 Nov 2022 11:24:27 +0000 Subject: [PATCH 1/2] Check for package tangles at build time See gh-17299 --- buildSrc/build.gradle | 5 + .../boot/build/JavaConventions.java | 6 +- .../architecture/ArchitecturePlugin.java | 65 +++++++++++ .../architecture/PackageTangleCheck.java | 102 ++++++++++++++++++ .../architecture/PackageTangleCheckTests.java | 90 ++++++++++++++++ .../architecture/tangled/TangledOne.java | 29 +++++ .../architecture/tangled/sub/TangledTwo.java | 29 +++++ .../architecture/untangled/UntangledOne.java | 29 +++++ .../untangled/sub/UntangledTwo.java | 27 +++++ 9 files changed, 380 insertions(+), 2 deletions(-) create mode 100644 buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitecturePlugin.java create mode 100644 buildSrc/src/main/java/org/springframework/boot/build/architecture/PackageTangleCheck.java create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/architecture/PackageTangleCheckTests.java create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/architecture/tangled/TangledOne.java create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/architecture/tangled/sub/TangledTwo.java create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/architecture/untangled/UntangledOne.java create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/architecture/untangled/sub/UntangledTwo.java diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 870e0568ff..08c8a97a3c 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -25,6 +25,7 @@ ext { dependencies { checkstyle "io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}" implementation(platform("org.springframework:spring-framework-bom:5.3.15")) + implementation("com.tngtech.archunit:archunit:1.0.0") implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4") implementation("commons-codec:commons-codec:1.13") implementation("org.apache.maven:maven-embedder:3.6.2") @@ -51,6 +52,10 @@ gradlePlugin { id = "org.springframework.boot.annotation-processor" implementationClass = "org.springframework.boot.build.processors.AnnotationProcessorPlugin" } + architecturePlugin { + id = "org.springframework.boot.architecture" + implementationClass = "org.springframework.boot.build.architecture.ArchitecturePlugin" + } autoConfigurationPlugin { id = "org.springframework.boot.auto-configuration" implementationClass = "org.springframework.boot.build.autoconfigure.AutoConfigurationPlugin" diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index decff985ca..e46d2c4180 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -48,6 +48,7 @@ import org.gradle.api.tasks.testing.Test; import org.gradle.testretry.TestRetryPlugin; import org.gradle.testretry.TestRetryTaskExtension; +import org.springframework.boot.build.architecture.ArchitecturePlugin; import org.springframework.boot.build.classpath.CheckClasspathForProhibitedDependencies; import org.springframework.boot.build.optional.OptionalDependenciesPlugin; import org.springframework.boot.build.testing.TestFailuresPlugin; @@ -61,8 +62,8 @@ import org.springframework.util.StringUtils; *