Skip to content

Commit de95a43

Browse files
committed
feat: Add versions-maven-plugin and convenient scripts
1 parent 111d8c6 commit de95a43

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import java.io.File
2+
import java.nio.file.Files
3+
import java.nio.file.attribute.PosixFilePermissions
24

35
// ─── Helpers ──────────────────────────────────────────────────────────────────
46

@@ -216,6 +218,7 @@ ${modulesXml}
216218
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
217219
<maven-surefire-plugin.version>3.5.5</maven-surefire-plugin.version>
218220
<modernizer-maven-plugin.version>3.4.0</modernizer-maven-plugin.version>
221+
<versions-maven-plugin.version>2.18.0</versions-maven-plugin.version>
219222
</properties>
220223
221224
<dependencyManagement>
@@ -289,6 +292,35 @@ ${dmXml}
289292
</execution>
290293
</executions>
291294
</plugin>
295+
<plugin>
296+
<groupId>org.codehaus.mojo</groupId>
297+
<artifactId>versions-maven-plugin</artifactId>
298+
<version>\${versions-maven-plugin.version}</version>
299+
<configuration>
300+
<ruleSet>
301+
<ignoreVersions>
302+
<ignoreVersion>
303+
<type>regex</type>
304+
<version>(?i).*-(alpha|beta|m|rc)([-.]?\\d+)?</version>
305+
</ignoreVersion>
306+
</ignoreVersions>
307+
<rules>
308+
<rule>
309+
<groupId>com.graphql-java</groupId>
310+
<artifactId>graphql-java-extended-scalars</artifactId>
311+
<ignoreVersions>
312+
<!-- ignore old versions starting with 2018, 2019, 2020, 2021, 2022, or 2023 that
313+
semantically are newer than current version scheme -->
314+
<ignoreVersion>
315+
<type>regex</type>
316+
<version>^20(1[8-9]|2[0-3]).*</version>
317+
</ignoreVersion>
318+
</ignoreVersions>
319+
</rule>
320+
</rules>
321+
</ruleSet>
322+
</configuration>
323+
</plugin>
292324
</plugins>
293325
</pluginManagement>
294326
<plugins>
@@ -306,6 +338,48 @@ writeFile(projectDir, 'parent/pom.xml', parentPom)
306338
// Remove the placeholder pom.xml that the archetype engine wrote at the project root
307339
new File(projectDir, 'pom.xml').delete()
308340

341+
// ─── Version-update helper scripts ────────────────────────────────────────────
342+
// Convenience wrappers around `mvnw versions:update-properties` so all property
343+
// versions can be bumped to their latest in one command. Written to the project
344+
// root for both Linux (LF, +x) and Windows (CRLF). Built from explicit line
345+
// lists so the line endings are correct regardless of this script's own endings.
346+
347+
writeFile(projectDir, 'mvn-update-properties-versions.sh', [
348+
'#!/bin/bash',
349+
'# Updates property versions to the latest found',
350+
'FILE=target/version-updates-applied.log',
351+
'mkdir -p target',
352+
'rm -f $FILE',
353+
'echo "Writing output to file $FILE"',
354+
'echo "Applying version updates specified as properties..."',
355+
'echo "======================================== PROPERTIES" >> $FILE',
356+
'./mvnw versions:update-properties >> $FILE',
357+
'',
358+
].join('\n'))
359+
360+
writeFile(projectDir, 'mvn-update-properties-versions.ps1', [
361+
'# Updates property versions to the latest found',
362+
'$FILE = "target/version-updates-applied.log"',
363+
'New-Item -ItemType Directory -Force -Path "target" | Out-Null',
364+
'if (Test-Path $FILE) { Remove-Item -Force $FILE }',
365+
'Write-Host "Writing output to file $FILE"',
366+
'Write-Host "Applying version updates specified as properties..."',
367+
'"======================================== PROPERTIES" | Out-File -FilePath $FILE -Append -Encoding utf8',
368+
'& ./mvnw.cmd versions:update-properties | Out-File -FilePath $FILE -Append -Encoding utf8',
369+
'',
370+
].join('\r\n'))
371+
372+
// Set the exec bit on the Linux script. POSIX filesystems only; on Windows
373+
// (non-POSIX) this throws UnsupportedOperationException and we fall back to the
374+
// best-effort Java executable flag (a no-op on Windows, but harmless).
375+
def shFile = new File(projectDir, 'mvn-update-properties-versions.sh')
376+
try {
377+
Files.setPosixFilePermissions(shFile.toPath(),
378+
PosixFilePermissions.fromString('rwxr-xr-x'))
379+
} catch (UnsupportedOperationException ignored) {
380+
shFile.setExecutable(true, false)
381+
}
382+
309383
// ─── common-domain ────────────────────────────────────────────────────────────
310384

311385
writeFile(projectDir, 'common-domain/pom.xml',

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ assert pmBlock.contains('<version>${modernizer-maven-plugin.version}</version>')
7676
assert pmBlock.contains('<javaVersion>${java.version}</javaVersion>') : 'modernizer must configure javaVersion'
7777
assert pmBlock.contains('<goal>modernizer</goal>') : 'modernizer pluginManagement must bind the modernizer goal'
7878

79+
// versions-maven-plugin: pinned and managed in pluginManagement with the update ruleSet
80+
assert parentPom.contains('<versions-maven-plugin.version>2.18.0</versions-maven-plugin.version>') \
81+
: 'parent must pin versions-maven-plugin version'
82+
assert pmBlock.contains('<artifactId>versions-maven-plugin</artifactId>') : 'versions-maven-plugin must be declared in pluginManagement'
83+
assert pmBlock.contains('<version>${versions-maven-plugin.version}</version>') : 'versions-maven-plugin pluginManagement must reference the version property'
84+
assert pmBlock.contains('<artifactId>graphql-java-extended-scalars</artifactId>') : 'versions-maven-plugin must configure the graphql-java-extended-scalars rule'
85+
7986
// the active <plugins> section is what remains of <build> after removing <pluginManagement>
8087
def buildBlock = (parentPom =~ /(?s)<build>.*<\/build>/)[0]
8188
def activePlugins = buildBlock.replaceAll(/(?s)<pluginManagement>.*<\/pluginManagement>/, '')
@@ -215,5 +222,21 @@ modules.findAll { it.startsWith('integration-') }.each { m ->
215222
: "${m} must configure maven-failsafe-plugin"
216223
}
217224

225+
// ── Version-update helper scripts at project root ─────────────────────────────
226+
// The .sh exec bit is POSIX-only and cannot be set when generating on Windows,
227+
// so it is intentionally not asserted here.
228+
229+
check('mvn-update-properties-versions.sh')
230+
check('mvn-update-properties-versions.ps1')
231+
232+
def shScript = text('mvn-update-properties-versions.sh')
233+
assert shScript.startsWith('#!/bin/bash') : 'bash script must start with the bash shebang'
234+
assert shScript.contains('./mvnw versions:update-properties') : 'bash script must run mvnw versions:update-properties'
235+
assert !shScript.contains('\r') : 'bash script must use LF line endings (no CR)'
236+
237+
def psScript = text('mvn-update-properties-versions.ps1')
238+
assert psScript.contains('mvnw.cmd versions:update-properties') : 'PowerShell script must run mvnw.cmd versions:update-properties'
239+
assert psScript.contains('\r\n') : 'PowerShell script must use CRLF line endings'
240+
218241
_buildLog.append("\n=== PASSED ===\n")
219242
true

0 commit comments

Comments
 (0)