asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
286 stars 122 forks source link

Incompatible with Gradle 7.6 #655

Closed Goooler closed 10 months ago

Goooler commented 1 year ago

You can repro this issue on https://github.com/apache/groovy/pull/1832.

> Task :groovy-ant:asciidoctor
Dependency verification has been disabled for configuration detachedConfiguration2
Dependency verification has been disabled for configuration detachedConfiguration3
Error: Exception in thread "main" java.lang.NoClassDefFoundError: org/gradle/api/GradleException
    at org.gradle.internal.classpath.Instrumented.<clinit>(Instrumented.java:94)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.$instrumentedCallSiteArray(AsciidoctorJavaExec.groovy)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.$getCallSiteArray(AsciidoctorJavaExec.groovy)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.registerExtensions(AsciidoctorJavaExec.groovy)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.access$0(AsciidoctorJavaExec.groovy)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec$_run_closure2.doCall(AsciidoctorJavaExec.groovy:64)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec$_run_closure2.call(AsciidoctorJavaExec.groovy)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2359)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2344)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2385)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.run(AsciidoctorJavaExec.groovy:62)
    at org.asciidoctor.gradle.remote.AsciidoctorJavaExec.main(AsciidoctorJavaExec.groovy:49)
Caused by: java.lang.ClassNotFoundException: org.gradle.api.GradleException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 12 more
daniellansun commented 1 year ago

ping @ysb33r @aalmiray ;-)

ysb33r commented 1 year ago

Hey @daniellansun, please try to 4.0.0-alpha.1 release and tell me if it fixes the problem

Goooler commented 1 year ago

@ysb33r Seems not, see https://github.com/Goooler/groovy/commit/bba5f5c0e15ef1451c600796b4bb33b47d9f1557 https://github.com/Goooler/groovy/actions/runs/3814781422/jobs/6489327740

ysb33r commented 1 year ago

@daniellansun It seems to be happening when extensions are deserialised. Since this is not happening with Gradle 7.5.1, but with Gradle 7.6, it might be possible that some Gradle dependencies are being leaked.

Do any of the Groovy asciidoc extensions rely on Gradle code?

ysb33r commented 1 year ago

@daniellansun That seems to be the problem. If I apply this diff to your repo, the build passes.

diff --git a/build-logic/src/main/groovy/org.apache.groovy-asciidoctor.gradle b/build-logic/src/main/groovy/org.apache.groovy-asciidoctor.gradle
index 7b1d4bb3c3..b827285d3a 100644
--- a/build-logic/src/main/groovy/org.apache.groovy-asciidoctor.gradle
+++ b/build-logic/src/main/groovy/org.apache.groovy-asciidoctor.gradle
@@ -158,6 +158,7 @@ def htmlOutputSanityCheck = { file, text, errors ->

 asciidoctor {
     def errors = new LinkedHashSet<String>()
+    inProcess IN_PROCESS
     doFirst {
         def specTestDir = file('src/spec/test')
         if (specTestDir.exists()) {
daniellansun commented 1 year ago

@ysb33r Thanks a lot for your looking into the issue and giving the solution. @Goooler Could you try again?

Goooler commented 1 year ago

Still failed, see https://github.com/Goooler/groovy/commit/06d1e9b578654cc23a3cdd8f333cf41c295806b3 https://github.com/Goooler/groovy/actions/runs/3826304522/jobs/6509985057

ysb33r commented 1 year ago

Ah yes, that is the asciidoctorPdf task. Up to now we could not run that task IN_PROCESS, because Gradle workers leaked an incompatible version of snakeyaml onto the classpath. I'll check to see if that is still the case, given that much work has been done by the Gradle team in that area.

Otherwise, this is going to be a much bigger fix.

mrotteveel commented 1 year ago

Another option is to add the Gradle API explicitly to the classpath. For example:

//...

configurations {
    asciidocExtensions
}

dependencies {
    asciidocExtensions gradleApi()
}

asciidoctor {
    configurations 'asciidocExtensions'
    // ...
}

asciidoctorPdf {
    configurations 'asciidocExtensions'
    // ...
}

// ...
mrotteveel commented 1 year ago

The above suggests a potential fix is for the plugin itself to add the gradle API to the classpath when running asciidoctor.

Goooler commented 1 year ago

@mrotteveel Failed due to

An exception occurred applying plugin request [id: 'org.apache.groovy-core']
> Failed to apply plugin 'org.apache.groovy-core'.
   > Failed to apply plugin 'org.apache.groovy-base'.
      > Failed to apply plugin 'org.apache.groovy-asciidoctor'.
         > org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method asciidoctorPdf() for arguments [precompiled_OrgApacheGroovyAsciidoctor$_run_closure12@2b1d9078] on root project 'groovy' of type org.gradle.api.Project.

see https://github.com/Goooler/groovy/commit/5b881c894fdf161f5e2e59ea372972d84fc25dcb https://github.com/Goooler/groovy/actions/runs/3862782763/jobs/6584560388

mrotteveel commented 1 year ago

@Goooler That script doesn't seem to have org.asciidoctor.jvm.pdf as plugin, so remove the asciidoctorPdf definition. My fix worked (with 3.3.2) in https://github.com/FirebirdSQL/jaybird-manual/blob/master/build.gradle

Goooler commented 1 year ago

@Goooler That script doesn't seem to have org.asciidoctor.jvm.pdf as plugin, so remove the asciidoctorPdf definition. My fix worked (with 3.3.2) in https://github.com/FirebirdSQL/jaybird-manual/blob/master/build.gradle

Still can't, see https://github.com/Goooler/groovy/commit/8d006fad6b44032ff36ab44f4accf4f87c718aaa.

PacoVK commented 1 year ago

@ysb33r is there yet a fix? Using 4.0.0-alpha.1 still breaks. I would contribute if possible but need at least a bit of context