Skip to content

Commit 3d70153

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 <noreply@anthropic.com> Signed-off-by: Roger Sheen <roger@infotexture.net>
1 parent 914ca53 commit 3d70153

File tree

2 files changed

+53
-32
lines changed

2 files changed

+53
-32
lines changed

build.gradle

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.github.eerohele.DitaOtTask
2222
import com.github.eerohele.SaxonXsltTask
2323

2424
def getPropertyOrDefault(String name, def defaultValue) {
25-
hasProperty(name) ? findProperty(name) : defaultValue
25+
providers.gradleProperty(name).getOrElse(defaultValue)
2626
}
2727

2828
String ditaHome = getPropertyOrDefault('ditaHome', projectDir.getParent())
@@ -62,23 +62,25 @@ task extensionPoints(type: SaxonXsltTask) {
6262
}
6363

6464
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-
}
65+
def outputFile = layout.projectDirectory.file(ditavalFile)
66+
outputs.file(outputFile)
7267

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')
68+
doLast {
69+
// Use Gradle's built-in OS detection instead of Ant
70+
def platformName = 'unix' // default
71+
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
72+
platformName = 'windows'
73+
} else if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
74+
platformName = 'mac'
8175
}
76+
77+
// Generate the ditaval file using modern Gradle file operations
78+
outputFile.asFile.text = """<?xml version="1.0" encoding="UTF-8"?>
79+
<val>
80+
<prop action="include" att="platform" val="${platformName}"/>
81+
<prop action="exclude" att="platform"/>
82+
</val>
83+
"""
8284
}
8385
}
8486

@@ -89,7 +91,7 @@ task generatePropertiesTemplate(type: SaxonXsltTask) {
8991
}
9092

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

9597
task pdf(type: DitaOtTask, dependsOn: autoGenerate) {
@@ -141,31 +143,39 @@ task htmlhelp(type: DitaOtTask, dependsOn: autoGenerate) {
141143
}
142144

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

152160
task cleanUp {
153161
doLast {
154-
ant.delete(dir: outputDir)
162+
delete outputDir
155163
}
156164
}
157165

158-
def commit = new ByteArrayOutputStream()
166+
// Create a configuration-cache compatible provider for git commit
167+
def gitCommitProvider = providers.exec {
168+
commandLine('git', 'rev-parse', 'HEAD')
169+
}.standardOutput.asText.map { it.trim() }
159170

160171
task gitMetadata {
161-
doLast {
162-
exec {
163-
workingDir = projectDir
164-
commandLine 'git'
165-
args = ['rev-parse', 'HEAD']
166-
standardOutput = commit
172+
// This task is kept for compatibility but git commit is now handled via provider
173+
doLast {
174+
logger.info("Git commit: ${gitCommitProvider.get()}")
167175
}
168-
}
176+
177+
// Mark outputs to help with up-to-date checking
178+
outputs.upToDateWhen { false } // Always run since git commit changes frequently
169179
}
170180

171181
task site(type: DitaOtTask) {
@@ -177,11 +187,14 @@ task site(type: DitaOtTask) {
177187

178188
transtype 'org.dita-ot.html'
179189

190+
// Evaluate the noCommitMeta flag at configuration time
191+
def includeCommitMeta = !providers.gradleProperty('noCommitMeta').map { Boolean.parseBoolean(it) }.getOrElse(false)
192+
180193
properties {
181194
property(name: 'args.gen.task.lbl', value: 'YES')
182195
property(name: 'args.rellinks', value: 'noparent')
183-
if (!(project.hasProperty('noCommitMeta') && Boolean.parseBoolean(project.property('noCommitMeta')))) {
184-
property(name: 'commit', value: commit)
196+
if (includeCommitMeta) {
197+
property(name: 'commit', value: gitCommitProvider)
185198
}
186199
}
187200
}

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)