Skip to content

Commit 19a32c3

Browse files
jeffjensenclaude
andcommitted
feat(arch): Group generated pom dependencies into TEST, PROD sections
Every generated child-module <dependencies> block is now split into a "<!-- TEST -->" section (scope 'test', emitted first) and a "<!-- PROD -->" section (everything else), with both header comments always present. The archetype currently emits only compile-scope dependencies, so they sit under PROD while TEST stands ready as a placeholder for test-scoped dependencies. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FTaQTM9wYTXLvvgCXSwhRm
1 parent e1e9402 commit 19a32c3

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/main/resources/META-INF/archetype-post-generate.groovy

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,32 @@ def failsafeSection = """\
7777

7878
/** Builds a child-module pom.xml string (2-space indent).
7979
* A dependency entry is either a String (an internal module artifactId, inheriting this project's
80-
* groupId and BOM-managed version) or a Map [groupId:…, artifactId:…] for an external dependency. */
80+
* groupId and BOM-managed version) or a Map [groupId:…, artifactId:…, scope:…] for an external
81+
* dependency. Dependencies are grouped into a "<!-- TEST -->" section (scope 'test', emitted first)
82+
* and a "<!-- PROD -->" section (everything else); both headers are always present. */
8183
def modulePom = { String gId, String parentAId, String ver,
8284
String aId, String desc, List deps = [], String buildSection = '' ->
8385
def depsSection = ''
8486
if (deps) {
85-
def lines = deps.collect { dep ->
87+
def renderDep = { dep ->
8688
def dGroup = (dep instanceof Map) ? dep.groupId : gId
8789
def dArtifact = (dep instanceof Map) ? dep.artifactId : dep
90+
def dScope = (dep instanceof Map && dep.scope) ? "\n <scope>${dep.scope}</scope>" : ''
8891
"""\
8992
<dependency>
9093
<groupId>${dGroup}</groupId>
91-
<artifactId>${dArtifact}</artifactId>
94+
<artifactId>${dArtifact}</artifactId>${dScope}
9295
</dependency>"""
93-
}.join('\n')
94-
depsSection = "\n <dependencies>\n${lines}\n </dependencies>\n"
96+
}
97+
def isTest = { it instanceof Map && it.scope == 'test' }
98+
def testLines = deps.findAll(isTest).collect(renderDep).join('\n')
99+
def prodLines = deps.findAll { !isTest(it) }.collect(renderDep).join('\n')
100+
def section = [' <!-- TEST -->']
101+
if (testLines) section << testLines
102+
section << ''
103+
section << ' <!-- PROD -->'
104+
if (prodLines) section << prodLines
105+
depsSection = "\n <dependencies>\n${section.join('\n')}\n </dependencies>\n"
95106
}
96107

97108
"""\

src/test/resources/projects/full/verify.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,13 @@ assert text("domain-graphql/src/main/java/${p}/domain/graphql/package-info.java"
239239
assert text('common-domain/pom.xml') =~ /<description>[^<]*\.<\/description>/ \
240240
: 'pom descriptions must be sentences ending with a period'
241241

242+
// ── dependency lists are split into TEST and PROD sections (TEST first) ──────
243+
244+
def depPom = text('domain-db-users/pom.xml')
245+
assert depPom.contains('<!-- TEST -->') : 'dependency list must carry a TEST section header'
246+
assert depPom.contains('<!-- PROD -->') : 'dependency list must carry a PROD section header'
247+
assert depPom.indexOf('<!-- TEST -->') < depPom.indexOf('<!-- PROD -->') : 'TEST section must come before PROD'
248+
assert depPom.indexOf('<!-- PROD -->') < depPom.indexOf('<artifactId>common-domain</artifactId>') : 'compile-scope deps must sit under PROD'
249+
242250
_buildLog.append("\n=== PASSED ===\n")
243251
true

src/test/resources/projects/spring-off/verify.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,13 @@ modules.each { m ->
9393
assert text('acceptance-tests/pom.xml').contains('<artifactId>maven-failsafe-plugin</artifactId>') : 'acceptance-tests must configure maven-failsafe-plugin'
9494
assert text('integration-db-users/pom.xml').contains('<artifactId>maven-failsafe-plugin</artifactId>') : 'integration module must configure maven-failsafe-plugin'
9595

96+
// ── dependency lists are split into TEST and PROD sections (TEST first) ──────
97+
98+
def svcPom = text('service/pom.xml')
99+
assert svcPom.contains('<!-- TEST -->') : 'dependency list must carry a TEST section header'
100+
assert svcPom.contains('<!-- PROD -->') : 'dependency list must carry a PROD section header'
101+
assert svcPom.indexOf('<!-- TEST -->') < svcPom.indexOf('<!-- PROD -->') : 'TEST section must come before PROD'
102+
assert svcPom.indexOf('<!-- PROD -->') < svcPom.indexOf('<artifactId>domain-service</artifactId>') : 'compile-scope deps must sit under PROD'
103+
96104
_buildLog.append("\n=== PASSED ===\n")
97105
true

0 commit comments

Comments
 (0)