Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.github.jruby-gradle.base 2.0.0 not working when use kotlin DSL #407

Open
blling opened this issue Jun 3, 2020 · 12 comments
Open

com.github.jruby-gradle.base 2.0.0 not working when use kotlin DSL #407

blling opened this issue Jun 3, 2020 · 12 comments

Comments

@blling
Copy link

blling commented Jun 3, 2020

I configed like this:

plugins {
    id("com.github.jruby-gradle.base") version "2.0.0"
}

repositories{
   // Unresolved reference: ruby
    ruby.gems()
}

but i get an error Unresolved reference: ruby

@ciscoo
Copy link

ciscoo commented May 25, 2021

The way this plugin configures the gems repository is a bit of a convoluted IMO and uses internals of Gradle from what I can tell. This just does not play nice with the Kotlin DSL.

import com.github.jrubygradle.api.core.RepositoryHandlerExtension

val repositoriesInternal = repositories as ExtensionAware
repositoriesInternal.extensions.configure(RepositoryHandlerExtension::class) {
    gems()
}

This likely stems from the wide support of Gradle version judging from:

repositories is decorated as ExtensionAware internally by Gradle:

You can confirm this yourself by printing the class:

println(repositories::class)
// class org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler_Decorated

The Javadoc for Instantiator says: (emphasis mine)

An implementation may accept abstract classes or interfaces and provide implementations for the missing pieces, for example providing an implementation of ExtensionAware.

So the "fix" from to get this plugin to nicely with the Kotlin DSL:

  1. Drop Groovy for Java as the implementation language for this plugin.
  2. Use as much of the public Gradle API as possible, where applicable.

I do not know enough about this plugin to say those two points are accurate. I wanted to use Asciidoctor Diagram and went down a rabbit hole trying to figure out how to configure it which led me here since our projects use Kotlin DSL.

cc @ysb33r

@ysb33r
Copy link
Contributor

ysb33r commented May 27, 2021

Thanks for raising this! There is a lot of older code that needs clean up in these plugins and it will only happen if people find issues 😸

@ysb33r
Copy link
Contributor

ysb33r commented May 27, 2021

However, you should have had no need to go down to RepositoriesInternal, because as you said it is ExtensionAware. I'll look into this when I get a chance.

@ciscoo
Copy link

ciscoo commented May 29, 2021

Well, to my understanding of Gradle's codebase, repositories { } is made ExtensionAware at runtime. So the cast to ExtensionAware is needed in my snippet above because the Kotlin DSL extension for repositories { } references RepositoryHandler which has no references to ExtensionAware.

@Vampire
Copy link

Vampire commented Jun 7, 2021

While it would probably be nice if the plugin provides a ruby accessor,
the hoops are not that high and ugly as ciscoo depicted.
This should work fine:

repositories {
    this as ExtensionAware
    the<RepositoryHandlerExtension>().gems()
}

Disclaimer: this is untested as I don't use ruby, but it should work fine.

@pedromalta
Copy link

And using

repositories {
    this as ExtensionAware
    the<RepositoryHandlerExtension>().gem()
}

How would I add the gems? Below code

dependencies {
    gems("rubygems:aws-sdk-s3:1.42.0")
}

@Vampire
Copy link

Vampire commented Oct 7, 2021

Yes, that just works.
gems is a configuration added by the plugin, so there is an accessor generated so that you can use it like you wrote it.

@pedromalta
Copy link

pedromalta commented Oct 7, 2021

I get "unresolved reference"

Captura-de-tela-de-2021-10-07-13-10-41.png

@Vampire
Copy link

Vampire commented Oct 7, 2021

That's because you are using the legacy way to apply the plugin.
Use the plugins block, only then the accessors for Kotlin DSL usage are generated.

@pedromalta
Copy link

If I add the jruby to the plugins block like id("com.github.jruby-gradle.base") not even the "android" part is recognized. This part I have no idea why. That's why I used it the legacy way

@pedromalta
Copy link

Ok, fixed, thanks, you were right, I was mixing new with legacy way :)

@pedromalta
Copy link

pedromalta commented Oct 28, 2021

I found that using

repositories {
    this as ExtensionAware
    the<RepositoryHandlerExtension>().gem()
}

Breaks the release build.

> Failed to query the value of task ':app:collect<Flavor>ReleaseDependencies' property 'projectRepositories'.
> repo.url must not be nul

Any input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants