Skip to content

Commit 0101fe0

Browse files
committed
update ArchUnit-Examples dependencies on release
We automatically keep the code of the separate ArchUnit-Examples repository in sync with the `archunit-example` module in this repository. However, sometimes an example makes an update of the dependencies necessary (as seen in 1d1a990). Up to now this made it necessary to manually update the dependencies in ArchUnit-Examples, or the release will fail when testing the updated ArchUnit-Examples. We now keep the (production) dependencies of ArchUnit-Examples automatically in sync with the `archunit-example` module. Since ArchUnit-Examples should be purely driven from this repository, I think it's an okay compromise to simply keep a static template here and fully overwrite the build file. Changes to the root build file should always be controlled from this repository. Signed-off-by: Peter Gafert <[email protected]>
1 parent 2ea0e72 commit 0101fe0

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

build-steps/release/archunit-examples-utils.gradle

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
1+
import groovy.transform.Field
2+
13
ext.archunitExamplesGitRepo = 'TNG/ArchUnit-Examples.git'
24
ext.updateArchUnitExampleVersion = { File archUnitExampleDir ->
35
fileTree(archUnitExampleDir) {
46
include '**/build.gradle'
5-
}.each {File buildFile ->
7+
}.each { File buildFile ->
68
buildFile.text = buildFile.text.replaceAll(/(com\.tngtech\.archunit:archunit[^:]*:)[\w.-]*/, "\$1${version}")
79
}
810
}
911
ext.updateArchUnitExampleSources = { File targetArchUnitExampleDir ->
12+
updateArchUnitExampleDependencies(targetArchUnitExampleDir)
13+
updateArchUnitExampleJavaSources(targetArchUnitExampleDir)
14+
}
15+
16+
@Field
17+
String archUnitExamplesRootBuildFileContent = """
18+
subprojects {
19+
apply plugin: 'java-library'
20+
21+
repositories {
22+
mavenCentral()
23+
}
24+
25+
dependencies {
26+
// These are the 'production' dependencies of the Demo src/main/java files -> just for Demo purposes, otherwise irrelevant
27+
#{dependencies}
28+
}
29+
}
30+
""".trim()
31+
32+
private void updateArchUnitExampleDependencies(File targetArchUnitExampleDir) {
33+
def buildFile = new File(targetArchUnitExampleDir, 'build.gradle')
34+
35+
List<Map<String, String>> sortedDependencies = archUnitExamplesMainDependencies.collect()
36+
.sort { first, second -> first.group <=> second.group ?: first.name <=> second.name }
37+
def dependencyIndent = ' ' * 8
38+
List<String> dependencyLines = sortedDependencies
39+
.collect { "${dependencyIndent}implementation '${it.group}:${it.name}:${it.version}'".toString() }
40+
41+
buildFile.text = archUnitExamplesRootBuildFileContent.replace('#{dependencies}', dependencyLines.join('\n')) // always Unix line separator
42+
}
43+
44+
private List updateArchUnitExampleJavaSources(File targetArchUnitExampleDir) {
1045
['example-plain', 'example-junit4', 'example-junit5'].each { exampleFolder ->
1146
def targetSource = new File(new File(targetArchUnitExampleDir, exampleFolder), 'src')
1247
targetSource.deleteDir()

buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ archUnitTest {
1010
providesTestJar = true
1111
}
1212

13+
rootProject.ext.archUnitExamplesMainDependencies = [
14+
dependency.jodaTime,
15+
dependency.javaxAnnotationApi,
16+
dependency.jakartaInject,
17+
dependency.jakartaAnnotations,
18+
dependency.springBeans,
19+
dependency.guice,
20+
dependency.geronimoEjb,
21+
dependency.geronimoJpa
22+
]
23+
1324
dependencies {
1425
// `api` dependencies so we can access them within `archunit-integration-test`
15-
api dependency.jodaTime
16-
api dependency.javaxAnnotationApi
17-
api dependency.jakartaInject
18-
api dependency.jakartaAnnotations
19-
api dependency.springBeans
20-
api dependency.guice
21-
api dependency.geronimoEjb
22-
api dependency.geronimoJpa
26+
archUnitExamplesMainDependencies.each { api it }
2327

2428
testImplementation project(path: ':archunit')
2529
}

0 commit comments

Comments
 (0)