Open blling opened 4 years ago
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:
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
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 :smile_cat:
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.
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
.
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.
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")
}
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.
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.
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
Ok, fixed, thanks, you were right, I was mixing new with legacy way :)
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?
I configed like this:
but i get an error
Unresolved reference: ruby