Skip to content

Commit 95498de

Browse files
infotextureclaude
andcommitted
Refactor for Gradle 9 compatibility
Use Cursor’s `claude-4-sonnet` model to replace deprecated constructs from Gradle 7 and earlier versions with their Gradle 8 and 9 equivalents to quiet deprecation warnings. Co-Authored-By: Claude <[email protected]> Signed-off-by: Roger Sheen <[email protected]>
1 parent 914ca53 commit 95498de

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

build.gradle

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ dependencies {
2020

2121
import com.github.eerohele.DitaOtTask
2222
import com.github.eerohele.SaxonXsltTask
23+
import org.gradle.process.ExecOperations
2324

2425
def getPropertyOrDefault(String name, def defaultValue) {
25-
hasProperty(name) ? findProperty(name) : defaultValue
26+
providers.gradleProperty(name).getOrElse(defaultValue)
2627
}
2728

2829
String ditaHome = getPropertyOrDefault('ditaHome', projectDir.getParent())
@@ -62,23 +63,25 @@ task extensionPoints(type: SaxonXsltTask) {
6263
}
6364

6465
task generatePlatformFilter {
65-
ant.condition(property: 'platform', value: 'windows') {
66-
os(family: 'windows')
67-
}
68-
69-
ant.condition(property: 'platform', value: 'mac' ) {
70-
os(family: 'mac')
71-
}
66+
def outputFile = layout.projectDirectory.file(ditavalFile)
67+
outputs.file(outputFile)
7268

73-
ant.condition(property: 'platform', value: 'unix' ) {
74-
os(family: 'unix')
75-
}
76-
77-
ant.echoxml(file: ditavalFile) {
78-
val {
79-
prop(action: 'include', att: 'platform', val: platform)
80-
prop(action: 'exclude', att: 'platform')
69+
doLast {
70+
// Use Gradle's built-in OS detection instead of Ant
71+
def platformName = 'unix' // default
72+
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
73+
platformName = 'windows'
74+
} else if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
75+
platformName = 'mac'
8176
}
77+
78+
// Generate the ditaval file using modern Gradle file operations
79+
outputFile.asFile.text = """<?xml version="1.0" encoding="UTF-8"?>
80+
<val>
81+
<prop action="include" att="platform" val="${platformName}"/>
82+
<prop action="exclude" att="platform"/>
83+
</val>
84+
"""
8285
}
8386
}
8487

@@ -89,7 +92,7 @@ task generatePropertiesTemplate(type: SaxonXsltTask) {
8992
}
9093

9194
task autoGenerate(dependsOn: [messages, params, extensionPoints, generatePlatformFilter, generatePropertiesTemplate]) {
92-
description 'Run tasks that generate content from resource files and the build environment.'
95+
description = 'Run tasks that generate content from resource files and the build environment.'
9396
}
9497

9598
task pdf(type: DitaOtTask, dependsOn: autoGenerate) {
@@ -141,31 +144,40 @@ task htmlhelp(type: DitaOtTask, dependsOn: autoGenerate) {
141144
}
142145

143146
doLast {
144-
ant.move(todir: outputDir, failonerror: 'no') {
145-
fileset(dir: "${outputDir}/htmlhelp", includes: '*.chm')
147+
// Move .chm files using modern Gradle file operations
148+
def htmlhelpDir = file("${outputDir}/htmlhelp")
149+
if (htmlhelpDir.exists()) {
150+
copy {
151+
from htmlhelpDir
152+
into outputDir
153+
include '*.chm'
154+
}
155+
// Clean up the htmlhelp directory
156+
delete htmlhelpDir
146157
}
147-
148-
ant.delete(dir: "${outputDir}/htmlhelp")
149158
}
150159
}
151160

152161
task cleanUp {
153162
doLast {
154-
ant.delete(dir: outputDir)
163+
delete outputDir
155164
}
156165
}
157166

158-
def commit = new ByteArrayOutputStream()
167+
// Create a lazy provider for git commit that resolves at task execution time
168+
def gitCommitProvider = providers.exec {
169+
commandLine('git', 'rev-parse', 'HEAD')
170+
}.standardOutput.asText.map { it.trim() }
159171

160172
task gitMetadata {
161-
doLast {
162-
exec {
163-
workingDir = projectDir
164-
commandLine 'git'
165-
args = ['rev-parse', 'HEAD']
166-
standardOutput = commit
173+
// This task ensures git metadata is available when needed by other tasks
174+
doLast {
175+
// Force provider evaluation to ensure git command runs
176+
logger.info("Git commit: ${gitCommitProvider.get()}")
167177
}
168-
}
178+
179+
// Mark outputs to help with up-to-date checking
180+
outputs.upToDateWhen { false } // Always run since git commit changes frequently
169181
}
170182

171183
task site(type: DitaOtTask) {
@@ -177,11 +189,15 @@ task site(type: DitaOtTask) {
177189

178190
transtype 'org.dita-ot.html'
179191

192+
// Evaluate the noCommitMeta flag at configuration time
193+
def includeCommitMeta = !providers.gradleProperty('noCommitMeta').map { Boolean.parseBoolean(it) }.getOrElse(false)
194+
180195
properties {
181196
property(name: 'args.gen.task.lbl', value: 'YES')
182197
property(name: 'args.rellinks', value: 'noparent')
183-
if (!(project.hasProperty('noCommitMeta') && Boolean.parseBoolean(project.property('noCommitMeta')))) {
184-
property(name: 'commit', value: commit)
198+
if (includeCommitMeta) {
199+
// Resolve the provider to get actual commit hash value
200+
property(name: 'commit', value: gitCommitProvider.get())
185201
}
186202
}
187203
}

gradle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# Fix Java memory errors with Gradle 5.2
22
org.gradle.jvmargs = -Xmx1024m
3+
4+
# Gradle 8 features for better performance and caching
5+
# ↓ Not supported by eerohele/dita-ot-gradle ↓
6+
# org.gradle.configuration-cache=true
7+
# org.gradle.configuration-cache.problems=warn
8+
# ↑ Not supported by eerohele/dita-ot-gradle ↑
9+
org.gradle.parallel=true
10+
org.gradle.caching=true

0 commit comments

Comments
 (0)