In case someone else want to do this, here's what I did to get the
workaround working:
1. Add the dependencies:
implementation "org.apache.groovy:groovy:4.0.27"
// only needed for groovydoc so limit to compilescope
compileOnly "org.apache.groovy:groovy-ant:4.0.27"
compileOnly "org.apache.groovy:groovy-templates:4.0.27"
compileOnly 'com.github.javaparser:javaparser-core:3.26.4'
2. Register a new groovydoc task since overriding tasks are deprecated
in gradle
tasks.register('antGroovydoc', DefaultTask){ group ='documentation' description
='Generate Groovydoc using Ant with custom config' doLast{ def outputDir
=layout.buildDirectory.dir("groovydocant").get().asFile ant.taskdef(
name:'groovydoc',
classname:'org.codehaus.groovy.ant.Groovydoc',
classpath: sourceSets.main.compileClasspath.asPath )
ant.groovydoc(
destdir: outputDir,
sourcepath: sourceSets.main.groovy.srcDirs.join(':'),
packagenames:'*',
javaVersion:'JAVA_21' )
} }
3. Make the new groovytask part of the normal build (optional)
tasks.named('build'){ dependsOntasks.named('antGroovydoc')
}
4. Make sure javadocJar picks up the new location
tasks.register('javadocJar', Jar){ dependsOntasks.named('antGroovydoc')
archiveClassifier.set('javadoc')
fromlayout.buildDirectory.dir("groovydocant")
}
Regards,
Per
On 5/29/25 10:13, Per Nyfelt wrote:
Great, thanks Paul! The workaround using ant directly in gradle works
fine!
I created a feature request to support the javaVersion property to the
gradle team here https://github.com/gradle/gradle/issues/33659.
Best regards,
Per
On 5/29/25 08:52, Paul King wrote:
Yes, Gradle doesn't know about those 4.0.27 changes yet. Feel free to
pester them to add that in an upcoming Gradle release.
For now, you can create a custom groovy task, sort of like where
Grails is possibly headed:
https://github.com/apache/grails-core/blob/groovydoc-tool-rewrite/buildSrc/src/main/groovy/org/apache/grails/internal/build/GrailsGroovydocWorker.groovy
Or, just call the commandline or Ant task making sure that Groovy
4.0.27 (groovy, groovy-groovydoc, groovy-ant if using ant) is on the
classpath:
tasks.register('runGroovyDoc', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.codehaus.groovy.tools.groovydoc.Main'
args = ['-d', 'build/groovydoc', '-sourcepath',
sourceSets.main.groovy.srcDirs.join(':'), '-javaVersion', 'JAVA_17',
'.']
}
tasks.register('runGroovyDocAnt') {
doLast {
ant.taskdef(name: 'groovydoc', classname:
'org.codehaus.groovy.ant.Groovydoc', classpath:
sourceSets.main.runtimeClasspath.asPath)
ant.groovydoc(
destdir: 'build/groovydocant',
sourcepath: sourceSets.main.groovy.srcDirs.join(':'),
packagenames: '*',
javaVersion: 'JAVA_17') {
}
}
}
Cheers,
Paul.
On Thu, May 29, 2025 at 5:07 AM Per Nyfelt <p...@alipsa.se> wrote:
Hi,
I am keen to use the new javaVersion property added to GroovyDoc in
4.0.27 but cannot figure it out. According to the gradle
documentation, "The version of the Groovydoc that is used, is the
one from the Groovy dependency defined in the build script." so i
did this:
add implementation `"org.apache.groovy:groovy-ant:4.0.27"` to
dependencies
add a groovydoc config
groovydoc {
docTitle = "${project.name} ${project.version}"
windowTitle = "${project.name} ${project.version}"
link 'https://docs.oracle.com/en/java/javase/21/docs/api/',
'java.'
javaVersion = 'JAVA_21'
}
But gradle is unhappy with this:
Could not set unknown property 'javaVersion' for task
':matrix-spreadsheet:groovydoc' of type
org.gradle.api.tasks.javadoc.Groovydoc.
Has anyone got this to work and could share some insights?