Skip to content

Commit

Permalink
Support removal of main property in Gradle 8.0
Browse files Browse the repository at this point in the history
- The main property is going to be replaced by mainClass in the JavaExec class.
- Dynamically attempt to continue calling the original property, but upon failure call the new property instead.
  • Loading branch information
tresat committed Aug 8, 2022
1 parent 676f805 commit 4c8b631
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class AbstractAsciidoctorTask extends AbstractAsciidoctorBaseTask {
configureForkOptions(jes)
logger.debug "Running AsciidoctorJ instance with environment: ${jes.environment}"
jes.with {
main = AsciidoctorJavaExec.canonicalName
setExecClass(jes, AsciidoctorJavaExec.canonicalName)
classpath = javaExecClasspath
args execConfigurationData.absolutePath
}
Expand All @@ -594,6 +594,19 @@ class AbstractAsciidoctorTask extends AbstractAsciidoctorBaseTask {
executorConfigurations
}

/** The main property will be removed in Gradle 8.0 and replaced by the mainClass property.
*
* Attempt to use the main property, and if the method doesn't exist try the replacement.
*/
@CompileDynamic
private void setExecClass(JavaExecSpec jes, String execClass) {
try {
jes.main = execClass
} catch (NoSuchMethodError e) {
jes.mainClass = execClass
}
}

private void copyResourcesByBackend(
Iterable<ExecutorConfiguration> executorConfigurations,
Optional<String> lang
Expand Down

0 comments on commit 4c8b631

Please sign in to comment.