Fixing Kotlin annotations architecture rule

See gh-34276
This commit is contained in:
Brian Clozel
2025-01-17 17:57:25 +01:00
parent 1bd9848d42
commit 309f5bebdb

View File

@@ -16,6 +16,7 @@
package org.springframework.build.architecture;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
@@ -66,8 +67,14 @@ abstract class ArchitectureRules {
static ArchRule javaClassesShouldNotImportKotlinAnnotations() {
return ArchRuleDefinition.noClasses()
.that().haveSimpleNameNotEndingWith("Kt")
.and().haveSimpleNameNotEndingWith("Dsl")
.that(new DescribedPredicate<JavaClass>("is not a Kotlin class") {
@Override
public boolean test(JavaClass javaClass) {
return javaClass.getSourceCodeLocation()
.getSourceFileName().endsWith(".java");
}
}
)
.should().dependOnClassesThat()
.resideInAnyPackage("org.jetbrains.annotations..")
.allowEmptyShould(true);