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
285 stars 120 forks source link

Gems don't work with Gradle >= 8.7 #725

Closed markslater closed 2 months ago

markslater commented 6 months ago

It seems that the org.asciidoctor.jvm.gems plugin is broken from Gradle 8.7 on, probably because of this bug in grolifant: https://gitlab.com/ysb33rOrg/grolifant/-/issues/137.

Reproducer

Given the following build.gradle.kts:

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id("org.asciidoctor.jvm.gems") version "4.0.2"
}

repositories {
    mavenCentral()
    ruby {
        gems()
    }
}

dependencies {
    asciidoctorGems("rubygems:asciidoctor-revealjs:5.1.0")
}

Under Gradle 8.6, ./gradlew clean asciidoctorGemsPrepare succeeds, but under Gradle 8.7, it fails with:

exception thrown for request to /rubygems/asciidoctor-revealjs/5.1.0/ivy.xml
java.lang.NoClassDefFoundError: Lorg/gradle/wrapper/ExclusiveFileAccessManager;
        at java.base/java.lang.Class.getDeclaredFields0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061)
        at java.base/java.lang.Class.getDeclaredFields(Class.java:2248)
        at org.codehaus.groovy.reflection.CachedClass$1.lambda$initValue$2(CachedClass.java:59)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at org.codehaus.groovy.reflection.CachedClass$1.initValue(CachedClass.java:62)
        at org.codehaus.groovy.reflection.CachedClass$1.initValue(CachedClass.java:54)
        at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:50)
        at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:37)
        at org.codehaus.groovy.reflection.CachedClass.getFields(CachedClass.java:256)
        at groovy.lang.MetaClassImpl.addFields(MetaClassImpl.java:2499)
        at groovy.lang.MetaClassImpl.inheritFields(MetaClassImpl.java:2494)
        at groovy.lang.MetaClassImpl.setupProperties(MetaClassImpl.java:2380)
        at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3421)
        at groovy.lang.MetaClassImpl.reinitialize(MetaClassImpl.java:3395)
        at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3388)
        at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:273)
        at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:315)
        at org.ysb33r.grolifant.api.core.ExclusiveFileAccess.$getStaticMetaClass(ExclusiveFileAccess.groovy)
        at org.ysb33r.grolifant.api.core.ExclusiveFileAccess.<init>(ExclusiveFileAccess.groovy)
        at org.ysb33r.gradle.jruby.internal.core.DefaultIvyXmlFactory.createIvyXml(DefaultIvyXmlFactory.groovy:152)
        at org.ysb33r.gradle.jruby.internal.core.DefaultIvyXmlFactory.ivyXmlPath(DefaultIvyXmlFactory.groovy:87)
        at org.ysb33r.gradle.jruby.internal.resolver.RatpackServerFactory.lambda$null$0(RatpackServerFactory.java:63)
        at ratpack.handling.internal.DefaultContext.next(DefaultContext.java:157)
        at ratpack.handling.internal.MethodHandler.handle(MethodHandler.java:44)
        at ratpack.handling.internal.DefaultContext.next(DefaultContext.java:157)
        at ratpack.handling.internal.DefaultContext.insert(DefaultContext.java:179)
        at ratpack.path.internal.PathHandler.handle(PathHandler.java:61)
        at ratpack.handling.internal.DefaultContext.next(DefaultContext.java:157)
        at ratpack.handling.internal.DefaultContext.lambda$start$4(DefaultContext.java:104)
        at ratpack.exec.internal.DefaultExecution.lambda$new$0(DefaultExecution.java:82)
        at ratpack.exec.internal.DefaultExecution$InitialExecStream.exec(DefaultExecution.java:403)
        at ratpack.exec.internal.DefaultExecution.exec(DefaultExecution.java:224)
        at ratpack.exec.internal.DefaultExecution.exec(DefaultExecution.java:217)
        at ratpack.exec.internal.DefaultExecution.drain(DefaultExecution.java:187)
        at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
        at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:73)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:335)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909)
        at ratpack.exec.internal.DefaultExecController$ExecControllerBindingThreadFactory.lambda$newThread$0(DefaultExecController.java:137)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.ExclusiveFileAccessManager
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
        at org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader.findClass(VisitableURLClassLoader.java:187)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:594)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
        ... 44 more
> Task :asciidoctorGemsPrepare FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':asciidoctorGemsPrepare'.
> Could not resolve all files for configuration ':asciidoctorGems'.
   > Could not resolve rubygems:asciidoctor-revealjs:5.1.0.
     Required by:
         project :
      > Could not resolve rubygems:asciidoctor-revealjs:5.1.0.
         > Could not get resource 'http://localhost:38881/rubygems/asciidoctor-revealjs/5.1.0/ivy.xml'.
            > Could not GET 'http://localhost:38881/rubygems/asciidoctor-revealjs/5.1.0/ivy.xml'. Received status code 500 from server: Internal Server Error

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 42s
2 actionable tasks: 2 executed

NB because of the vagaries of Gradle, it can take a little fiddling to make it actually use the 8.7 wrapper after upgrading from 8.6. I found stopping all Gradle daemons with ./gradlew --stop and removing the cache directory and rubygem cache directory (~/.gradle/caches and ~/.gradle/rubygems-ivyxml-cache2 by default) seemed to give it the nudge it needed.

abelsromero commented 5 months ago

I am happy waiting for 8.8 if the issue is located to Gradle 8.7. If I understand correctly, this is for both https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/725 and https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/726 right? and the issue is only with Gradle 8.7?

markslater commented 5 months ago

@abelsromero yes. I'll update the PR when Gradle 8.8 is available.

abelsromero commented 5 months ago

It's my opinion, other may differ.

ysb33r commented 5 months ago

Bumping the build to the latest version of grolifant should solve this issue

markslater commented 5 months ago

@ysb33r it does, but an issue with Gradle 8.7 itself causes spurious test failures. I just tested with Gradle 8.8-rc-1, and everything is working.

See #726 for a brief discussion with @abelsromero about how we should deal with it.

abelsromero commented 5 months ago

I think what @ysb33r is suggesting is that we could bump the version and make a release?

markslater commented 5 months ago

In that case, I'd suggest taking the current version of #726, which bumps grolifant to the latest version and tests it using 8.8-rc-1. We can then come back and switch the test to the production version of 8.8 when it's released.

markslater commented 4 months ago

@abelsromero , @ysb33r I've marked the pull request I created for fixing this as ready for review. Let me know what you think.