Hello, is it possible to use a groovy gradle plugi...
# gradle
a
Hello, is it possible to use a groovy gradle plugin which doesn’t have Plugin Market artifact with the kotlin dsl?
e
sure, you just have to tell Gradle how to find it manually
a
I’ve done it with the resolution strategy defined in settings.gradle
👍 1
using eachPlugin block
Could not apply requested plugin [id: ‘namespace.pluginName’, version: ‘4.0.0’, artifact: ‘namespacepluginName4.0.0’] as it does not provide a plugin with id ‘namespace.pluginName’
im getting that error
my settings file looks like this
Copy code
pluginManagement {
    repositories {
        maven(url = "uri")
        gradlePluginPortal()
        mavenCentral()
    }
    resolutionStrategy {
        eachPlugin {
            when(requested.id.namespace) {
                "my.namespace" -> useModule("${requested.id.namespace}:${requested.id.name}:${requested.version}")
            }
        }
    }
}
on build.gradle then i’m using
Copy code
plugins {
    id("my.namespace.pluginName") version "version"
}
s
Maybe there's some config missing in the plugin itself? In the plugin's own build script I would expect to see something like:
Copy code
gradlePlugin {
    plugins {
        register("My Plugin") {
            id = "namespace.pluginName"
            implementationClass = "com.example.Whatever"
        }
    }
}
I'm not sure how the wiring works there when there's no plugin marker, though...
a
hmm
e
gradlePlugin
creates metadata in the jar's
META-INF
for each declared plugin
👌 1
s
☝️ sounds like that could be the thing that's missing
e
this is how the plugins are found by ID after they're in the classpath, the marker is so that Gradle knows which artifacts to add to the classpath
👍 1
a
Ya I think thats what is missing we don’t have a gradlePlugin block in our build.gradle inside the plugins project just the publishing one!
With the kotlin dsl we cannot use the dependency like in groovy am I right?
s
Can you be more specific?
The snippet I shared is for a Kotlin build script
a
the buildscript { dependencies { … } } block in groovy doens’t require the plugins to have defined the gradlePlugin block
e
the META-INF/gradle-lugins/*.properties metadata is how Gradle finds plugins by ID, both in Groovy and Kotlin DSL
buildscript { dependencies { ... } } is not a difference of Groovy vs Kotlin DSL
whether you use buildscript { ... } or plugins { ... } is the same in both DSLs
if you're just adding to the buildscript classpath and not `apply`ing a plugin, that's not a plugin
a
no, I’m adding it into the classpath and then applying it via
apply plugin: …
in groovy
and I wanted to be able to do that in kts
e
you're using the same ID as
apply plugin:
?
a
ya
e
as a first step you can try using the same
buildscript
+
apply
in gradle.kts, it should work just like in groovy, you just won't get any type-safe accessors
a
ok
let me try
the thing is he doens’t find it in the repos
ok my base setup that is working in groovy is the following:
Copy code
buildscript {
    repositories {
        clear()
        maven {
            url myRepo
        }
        mavenCentral()
    }

    dependencies {
        classpath 'namespace:plugin:version'
    }
}

apply plugin: "pluginId"
e
if you need a custom repo, it needs to go in
buildscript { repositories { ... } }
for buildscript, or
pluginManagement { repositories { ... } }
for plugins
a
I think i’ve figured it out finally
ya I have it inside pluginManagement
it was the way I was applying it
💪