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

Specify different repository for gem resolution #546

Open MarkusAmshove opened 4 years ago

MarkusAmshove commented 4 years ago

Hello,

I'm trying to use the gradle plugin behind a corporate proxy and took the gradle pdf example. I'm sitting behind a corporal proxy which won't let me resolve stuff from mavencentral, jcenter or ruby gems.

However, we do have Artifactory to proxy those repositories.

My build.gradle looks like this:

buildscript {
    repositories {
        maven {
            url 'http://corporation/artifactory/java-repos'
        }
    }
    dependencies {
        classpath 'org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.2.0'
        classpath 'org.asciidoctor:asciidoctor-gradle-jvm-gems:3.2.0'
    }
}

apply plugin: 'java'
apply plugin: 'org.asciidoctor.jvm.pdf'
apply plugin: 'org.asciidoctor.jvm.gems'

version = '1.0.0'

repositories {
    maven {
        url 'http://corporation/artifactory/java-repos'
    }
    ruby {
        gems 'http://corporation/artifactory/api/gems/ruby-remote'
    }
}

dependencies {
  asciidoctorGems 'rubygems:rouge:3.15.0'
}

asciidoctorPdf {
  dependsOn asciidoctorGemsPrepare

  baseDirFollowsSourceFile()

  asciidoctorj {
    requires 'rouge'
    attributes 'build-gradle': file('build.gradle'),
        'sourcedir': project.sourceSets.main.java.srcDirs[0],
        'endpoint-url': 'http://example.org',
        'source-highlighter': 'rouge',
        'imagesdir': './images',
        'toc': 'left',
        'icons': 'font',
        'idprefix': '',
        'idseparator': '-'
  }
}

// alias
task asciidoctor(dependsOn: asciidoctorPdf)

The Gradle and Java dependencies seem to resolve correctly, but I'm faced with the following error:

$ gradlew asciidoctor --console=plain

404 client error for request to /rubygems/rouge/3.15.0/ivy.xml
> 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 find rubygems:rouge:3.15.0.
     Searched in the following locations:
       - http://corporation/artifactory/java-repos/rubygems/rouge/3.15.0/rouge-3.15.0.pom
       - http://localhost:59605/rubygems/rouge/3.15.0/ivy.xml
     Required by:
         project :

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
1 actionable task: 1 executed

It doesn't seem to take the specified gem repository into account. Is there anything I can do to point asciidoctorGems to the correct repository?

ysb33r commented 4 years ago

@MarkusAmshove Is your corporate GEMs repo maven-based or rubygems-based?

By using ruby.gems you are setting up an internal proxy that will translate Gradle dependency requests in to requests for a service that implements rubygems. SO if your corporate Artifactory also supports GEM repositories using ruby.gems will work. If your Artifactory repo is already a translation of RubyGems into Maven (such as which Torquebox used to do), then you cannot use this approach and should rather just do maven { url = '....' }.

(Of course having said of that, there could always be a bug in the jruby-gradle core plugin w.r.t. to private repositories).

MarkusAmshove commented 4 years ago

@ysb33r that particular repository is gem based, as it can also work with ruby directly.

Do I have to tell gradle to use the gem protocol? The error is strange because it tries to resolve the dependency with the maven repository, which tells me it tries to resolve the maven way.

The Artifactory documentation also doesn't state JRuby for this repository type

ysb33r commented 4 years ago

Try using

    ruby.gems('http://corporation/artifactory/api/gems/ruby-remote')

This is just in case the closure delegation does not work correctly.

Basically in your case what should happen is that the internal proxy will query your artifact repo and then cache locally as Ivy repo.

If you run with --debug you should get quite a bit more information come out.

MarkusAmshove commented 4 years ago

I've tried ruby.gems('...') but got the same error.

I also tried to change the order of repositories:

repositories {
    ruby.gems('...')
    maven {
        url '...'
    }
}

and now the error order shifts (notice that localhost comes first now):

020-04-18T11:28:57.739+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not resolve all files for configuration ':asciidoctorGems'.
2020-04-18T11:28:57.739+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Could not find rubygems:rouge:3.15.0.
2020-04-18T11:28:57.739+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Searched in the following locations:
2020-04-18T11:28:57.739+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]        - http://localhost:55488/rubygems/rouge/3.15.0/ivy.xml
2020-04-18T11:28:57.739+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]        - http://corporation/artifactory/java-repos/rubygems/rouge/3.15.0/rouge-3.15.0.pom

I've also run the build with --debug and the specified gem url isn`t mentioned once in the log :-/

tkrah commented 2 years ago

Just want to add my 2 cents that this is not working for me too - same problem like @MarkusAmshove - I do have the correct ruby gem mirror configured and can browse the gem repo with my browser but if I run it via gradle it does not even look at the configured ruby.gems url but always going to use the configured maven repository instead (which I need too for other dependencies). Any hints to debug this further - "--debug" does not provide something valuable.

Seems like an upstream issue though because it does not work just using the jruby-gradle-plugin, reported here:

https://github.com/jruby-gradle/jruby-gradle-plugin/issues/429