Skip to content

Refactor archunit-maven-test build - #1751

Open
hankem wants to merge 4 commits into
mainfrom
refactor-archunit-maven-test-build
Open

hankem wants to merge 4 commits into
mainfrom
refactor-archunit-maven-test-build

Conversation

@hankem

@hankem hankem commented Oct 9, 2026

Copy link
Copy Markdown
Member
  • refactor build script to lazy task registration
  • fix publish task ordering (silently broken with 4779b3a)
  • simplify TestResultTest.assertMatchWith, show context of failure
  • redirect Maven test execution into log file to avoid flooding the console output

hankem added 4 commits October 9, 2026 10:46
Replace the deprecated `task` DSL, eager `tasks.create` calls and `tasks.findAll` wiring
with lazy `tasks.register`, keeping the returned `TaskProvider`s in variables
and inlining the task names that were previously built as separate string locals.

`dependsOn`, `onlyIf`, `finalizedBy` and `mustRunAfter` are now set in `configure` blocks,
the aggregate `runMavenTest` depends on the per-config variants via `tasks.named`,
and the JDK log line is attached through `tasks.configureEach`
instead of eagerly realizing every task during configuration.

Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
`allprojects` within `archunit-maven-test` only contains the project itself,
so the lookup of release projects for `mustRunAfter` wiring always returned an empty list.

The lookup was correct when it was introduced in 7a1cc96,
as the code then lived in `build-steps/maven-integration-test/`
and was applied from the root project, where `allprojects` spans the whole build.
It silently broke when 4779b3a moved the build config
verbatim into the `archunit-maven-test` subproject, changing the project context of the script.

Use `rootProject.allprojects` to consider the whole build again.

Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Redirect `executeRules` stdout and stderr into a log file
under `verificationResultArchivePath/<config.identifier>/`,
keeping the console output limited to the echoed command.

Also print the `verifyRules` command and the `cleanUpMavenTest` copy destination
for better traceability of the Maven integration test run.

Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
@schulzjo-tng schulzjo-tng self-assigned this Oct 9, 2026

@schulzjo-tng schulzjo-tng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice overall!

def logFile = new File(logPath, "${name}.log")
logStream = new FileOutputStream(logFile)
standardOutput = logStream
errorOutput = logStream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea. One thing I'm wondering about is debugging CI: In case this fails in the CI, do we want to publish these files as build artifacts? Otherwise, the output might not be obtainable.

dependsOn prepareMavenTest
}
executeRules.configure mavenExec {
commandLine mavenCommand('clean', 'test', '-P', 'execute-rules')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: do we want to move the commandLine between doFirst and doLast to make reading more intuitive? Applies to other tasks as well.

}
}
return result;
assertThat(failedArchitectureTests).as("actual failures").hasSameElementsAs(givenTestClasses.tests);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Comment on lines 212 to +215
// Run cleanUp even if task fails
[tasks[prepareMavenTest], tasks[verifyRules], tasks[executeRules]]*.finalizedBy tasks[cleanUpMavenTest]
[prepareMavenTest, verifyRules, executeRules].each { taskProvider ->
taskProvider.configure { finalizedBy cleanUpMavenTest }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: The "Run cleanUp even if task fails" does not work in either the old or new code (to test: comment out the for loop in TestResultTest.java:getFailedTests and execute runMavenTest). But I'm not sure I'd even want it, since not cleaning up can facilitate debugging. Leaving it up to you if you want to try to fix or remove it.

However: Now that we're cleaning up here, what do you think about a .gitignore in this directory for the temporary files? The following content works well:

/src
/pom.xml

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants