diff --git a/build-steps/release/archunit-examples-utils.gradle b/build-steps/release/archunit-examples-utils.gradle index 0f4ce46bc8..6c8edc1d82 100644 --- a/build-steps/release/archunit-examples-utils.gradle +++ b/build-steps/release/archunit-examples-utils.gradle @@ -1,12 +1,47 @@ +import groovy.transform.Field + ext.archunitExamplesGitRepo = 'TNG/ArchUnit-Examples.git' ext.updateArchUnitExampleVersion = { File archUnitExampleDir -> fileTree(archUnitExampleDir) { include '**/build.gradle' - }.each {File buildFile -> + }.each { File buildFile -> buildFile.text = buildFile.text.replaceAll(/(com\.tngtech\.archunit:archunit[^:]*:)[\w.-]*/, "\$1${version}") } } ext.updateArchUnitExampleSources = { File targetArchUnitExampleDir -> + updateArchUnitExampleDependencies(targetArchUnitExampleDir) + updateArchUnitExampleJavaSources(targetArchUnitExampleDir) +} + +@Field +String archUnitExamplesRootBuildFileContent = """ +subprojects { + apply plugin: 'java-library' + + repositories { + mavenCentral() + } + + dependencies { + // These are the 'production' dependencies of the Demo src/main/java files -> just for Demo purposes, otherwise irrelevant +#{dependencies} + } +} +""".trim() + +private void updateArchUnitExampleDependencies(File targetArchUnitExampleDir) { + def buildFile = new File(targetArchUnitExampleDir, 'build.gradle') + + List> sortedDependencies = archUnitExamplesMainDependencies.collect() + .sort { first, second -> first.group <=> second.group ?: first.name <=> second.name } + def dependencyIndent = ' ' * 8 + List dependencyLines = sortedDependencies + .collect { "${dependencyIndent}implementation '${it.group}:${it.name}:${it.version}'".toString() } + + buildFile.text = archUnitExamplesRootBuildFileContent.replace('#{dependencies}', dependencyLines.join('\n')) // always Unix line separator +} + +private List updateArchUnitExampleJavaSources(File targetArchUnitExampleDir) { ['example-plain', 'example-junit4', 'example-junit5'].each { exampleFolder -> def targetSource = new File(new File(targetArchUnitExampleDir, exampleFolder), 'src') targetSource.deleteDir() diff --git a/buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle b/buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle index 0ae6b384a7..1d00e5ea80 100644 --- a/buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle +++ b/buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle @@ -10,16 +10,20 @@ archUnitTest { providesTestJar = true } +rootProject.ext.archUnitExamplesMainDependencies = [ + dependency.jodaTime, + dependency.javaxAnnotationApi, + dependency.jakartaInject, + dependency.jakartaAnnotations, + dependency.springBeans, + dependency.guice, + dependency.geronimoEjb, + dependency.geronimoJpa +] + dependencies { // `api` dependencies so we can access them within `archunit-integration-test` - api dependency.jodaTime - api dependency.javaxAnnotationApi - api dependency.jakartaInject - api dependency.jakartaAnnotations - api dependency.springBeans - api dependency.guice - api dependency.geronimoEjb - api dependency.geronimoJpa + archUnitExamplesMainDependencies.each { api it } testImplementation project(path: ':archunit') } \ No newline at end of file