Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ArchUnit-Examples dependencies on release #1290

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}