Skip to content

Commit

Permalink
update ArchUnit-Examples dependencies on release
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
codecholeric committed Apr 11, 2024
1 parent 2ea0e72 commit 0101fe0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
37 changes: 36 additions & 1 deletion build-steps/release/archunit-examples-utils.gradle
Original file line number Diff line number Diff line change
@@ -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<Map<String, String>> sortedDependencies = archUnitExamplesMainDependencies.collect()
.sort { first, second -> first.group <=> second.group ?: first.name <=> second.name }
def dependencyIndent = ' ' * 8
List<String> 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()
Expand Down
20 changes: 12 additions & 8 deletions buildSrc/src/main/groovy/archunit.java-examples-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

0 comments on commit 0101fe0

Please sign in to comment.