asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
623 stars 173 forks source link

Asciidoctorj cannot load external GEMs anymore #1136

Open ysb33r opened 1 year ago

ysb33r commented 1 year ago

I don't think asciidoctorj handles external GEMs correctly anymore. My starting point for this is https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/658. After I could not figure out what the issue was in the Gradle plugin, I went straight to the asciidoctorj command-line to reproduce the issue

gem install --user-install --platform jruby asciidoctor-bibtex
sdk install asciidoctorj 2.5.7
sdk use asciidoctorj 2.5.7
GEM_HOME=$(cd ~/.local/share/gem/ruby; pwd) asciidoctorj -r asciidoctor-bibtex  -a bibtex-file=$(pwd)/biblio.bib index.adoc 

(The location for GEM_HOME might differ depending on the specific system).

The results in the error

Exception in thread "main" org.jruby.exceptions.LoadError: (LoadError) no such file to load -- asciidoctor-bibtex
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1017)
    at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85)
    at RUBY.<main>(<script>:1)

A simple index.adoc to use for testing is

= Example bibtex

Some citation: cite:[Bogus1a]

and the corresponding biblio.bib

@book{Bogus1a,
    author = {J. Bloggs},
    title =  {Book title},
    publisher = {Publisher},
    year =   {2018}
}

I tested it with Asciidoctor Ruby command-line and it works, so this is definitely an AsciidoctorJ issue.

robertpanzer commented 1 year ago

Right now this is the intended behavior, and it's even tested: https://github.com/asciidoctor/asciidoctorj/blob/b425925aef5830afa9970b3082269f4d149bb6ba/asciidoctorj-core/build.gradle#L123-L137 The change was introduced in AsciidoctorJ 1.6.0 with this PR: https://github.com/asciidoctor/asciidoctorj/pull/518

So right now I would say that this is the intended behavior, and iirc we did this because an old system installation of Asciidoctor could otherwise break asciidoctorj.

If my Google powers do not trick me, and requiring a gem on the GEM_PATH just adds it to the LOAD_PATH, it should be the same as passing it to asciidoctorj:

asciidoctorj -r asciidoctor-bibtex  -a bibtex-file=$(pwd)/biblio.bib -I /Users/rpanzer/.rvm/gems/ruby-2.7.2/gems/asciidoctor-bibtex-0.8.0/ index.adoc

I am happy to change AsciidoctorJ in whatever direction we like, but right now I'd say that this is the intended behavior.