This message was deleted.
# community-support
s
This message was deleted.
v
You mean publishing a precompiled script plugin? Yes, that is working expectedly and is also documented.
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompiled_plugins > Precompiled script plugins > [...] > Precompiled script plugins are compiled into class files and packaged into a jar. For all intents and purposes, they are binary plugins and can be applied by plugin ID, tested and published as binary plugins. In fact, the plugin metadata for them is generated using the Gradle Plugin Development Plugin.
They are mainly syntactic sugar over writing a full-fledged class
o
So I went through that guide but yeah, "published" was rather concerning, because the section is about local
buildSrc
etc. But anyway, I am happy if it works and supported
I tried a pure plugin approach first, but it requires quite a lot of rewrite for a complex flow. So I will kick it down the road until after the plugin actually works
👌 1
@Vampire So it didn't quite work after a few experiments. Despite placing the file in "/src/groovy/org/wiremock.../wiremock-extension-convention.gradle", the id in
gradlePlugin
does not get a group ID. Moreover, these additions are called after
plugins.register()
so I cannot just remove previous definition and re-define the plugin like this one
Copy code
gradlePlugin {
    website = "<https://github.com/wiremock/gradle-wiremock-extension-plugins>"
    vcsUrl = "<https://github.com/wiremock/gradle-wiremock-extension-plugins>"
    plugins {
        removeIf { it.id.equals("wiremock-extension-convention") }
        register("wiremock-extension-convention") {
            id = "org.wiremock.tools.gradle.wiremock-extension-convention"
            implementationClass = "WiremockExtensionConventionPlugin"
            displayName = "Gradle convention plugin that bundles common packaging and release logic for WireMock extensions"
            description = "Gradle convention plugin for WireMock Extensions"
            tags = listOf("wiremock")
        }
    }
}
Well,
afterEvaluate()
hack actually worked...
Copy code
plugins {
        afterEvaluate {
            removeIf { it.id.equals("wiremock-extension-convention") }
            register("wiremock-extension-convention") {
                id = "org.wiremock.tools.gradle.wiremock-extension-convention"
                implementationClass = "WiremockExtensionConventionPlugin"
                displayName = "Gradle convention plugin that bundles common packaging and release logic for WireMock extensions"
                description = "Gradle convention plugin for WireMock Extensions"
                tags = listOf("wiremock")
            }
        }
    }
v
Don't use
afterEvaluate
. And also don`t use
plugins.register
why should you? For precompiled script plugins everything is setup automatically.
o
GroupID was not injected there despite being defined properly
v
For a Groovy DSL precompiled script plugin that should have ID
org.wiremock.tools.gradle.wiremock-extension-convention
just name the file
org.wiremock.tools.gradle.wiremock-extension-convention.gradle
That's not a group id, that's just part of the plugin id
For Kotlin DSL precompiled script plugins you can either name the file with the full ID, or put the prefix as package statement. For Groovy DSL precompiled script plugins just name the file with the full ID.
o
Ack, reverting that. Will check the doc and probably file a PR to make it more clear
👌 1
It is helpful to have tags & co, so maybe the hack has its uses anyway
Ofc a better solution would be having a method to amend configuration without removal. But AfterAll will work too, without removal
v
to make it more clear
This is not clear enough? :-)
To apply a precompiled script plugin, you need to know its ID which is derived from the plugin script’s filename (minus the
.gradle.kts
extension) and its (optional) package declaration.
For example, the script
src/main/kotlin/java-library-convention.gradle.kts
would have a plugin ID of
java-library-convention
(assuming it has no package declaration). Likewise,
src/main/kotlin/my/java-library-convention.gradle.kts
would result in a plugin ID of
my.java-library-convention
as long as it has a package declaration of
my
.
It is helpful to have tags & co
Just configure the plugin that is registered for you.
o
This is not clear enough? 🙂
Whell that's only for Kotlin 🙂
Well, I guess back to
afterEvaluate
Copy code
Execution failed for task ':publishPlugins'.
> Plugin 'org.wiremock.tools.gradle.wiremock-extension-convention' has no 'displayName' property set
v
Whell that's only for Kotlin 🙂
Just because Kotlin is the default DSL and I have the docs in Kotlin mode, sorry. Switch it to Groovy mode in any of the example blocks and you have
To apply a precompiled script plugin, you need to know its ID which is derived from the plugin script’s filename (minus the
.gradle
extension).
For example, the script
src/main/groovy/java-library-convention.gradle
would have a plugin ID of
java-library-convention
. Likewise,
src/main/groovy/my.java-library-convention.gradle
would result in a plugin ID of
my.java-library-convention
.
🙂
o
Anyway it doesn't work with the current version of Gradle Plugin that actually requires display name & Co to be set. It is an easy fix on the plug-in side I guess, but for now I just want to keep work around until later work everything to kotlin anyway
Would it be possible to approve the plugin hosting with such a workaround for testing purposes? The plug-in metadata is correct from what I see in the build results, so I think it would be okay
v
Anyway it doesn't work with the current version of Gradle Plugin that actually requires display name & Co to be set. It is an easy fix on the plug-in side I guess, but for now I just want to keep work around until later work everything to kotlin anyway
Let me ask again, why don't you just configure the plugin the was registered for you without using
afterEvaluate
? The main thing
afterEvaluate
does is adding timing problems, ordering problems, race conditions, and clutter, and it should be avoided wherever possible.
Copy code
gradlePlugin {
    plugins.matching { it.id == "org.wiremock.tools.gradle.wiremock-extension-convention" }.configureEach {
        displayName = "If you're happy and you know it clap your hands"
    }
}
Would it be possible to approve the plugin hosting with such a workaround for testing purposes? The plug-in metadata is correct from what I see in the build results, so I think it would be okay
I'm not sure what you mean
If you meant that you fear it will not be approved when you use
afterEvaluate
in the build building it, I highly doubt that this would have any influence. You are just shooting yourself in the foot. But I have no idea, I'm not affiliated to Gradle in any way.
o
You are just shooting yourself in the foot. But I have no idea, I'm not affiliated to Gradle in any way
Temporary for prototyping. The plugin will be moved to Kotlin and then reworked to classes
```gradlePlugin {
plugins.matching { it.id == "org.wiremock.tools.gradle.wiremock-extension-convention" }.configureEach {
displayName = "If you're happy and you know it clap your hands"
}
}```
I tried that, but the plugins container is empty at that point. I guess script hooks are called later, so it would need some additional tampering with task dependencies
v
> Temporary for prototyping. The plugin will be moved to Kotlin and then reworked to classes Yeah, well, as I said, I don't think that would have any influence. I don't think they would even do an analysis of the actual plugin code, let alone of the build building that plugin. > I tried that, but the plugins container is empty at that point. Shouldn't matter.
plugins.matching { ... }.configureEach { ... }
also configures things added in the future like for any other named domain object container.
o
OK, lemme try again
Just to confirm,
Copy code
gradlePlugin {
    website = "<https://github.com/wiremock/gradle-wiremock-extension-plugins>"
    vcsUrl = "<https://github.com/wiremock/gradle-wiremock-extension-plugins>"
    plugins.matching { it.id == "org.wiremock.tools.gradle.wiremock-extension-convention" }.configureEach {
        displayName = "Gradle convention plugin that bundles common packaging and release logic for WireMock extensions"
        description = "Gradle convention plugin for WireMock Extensions"
        tags = listOf("wiremock")
    }
}
... indeed results in
Copy code
> Task :publishPlugins FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishPlugins'.
> Plugin 'org.wiremock.tools.gradle.wiremock-extension-convention' has no 'displayName' property set
v
Oh, right, sorry. Don't match on
it.id
, but on
it.name
. For those generated plugin declarations the plugin id is also used as name and the
matching
is done as soon as the object is added to the
plugins
container and before the precompiled Groovy script plugin plugin had the chance to set the
id
field. But the
name
is already present. So with
it.name == "org.wiremock.tools.gradle.wiremock-extension-convention"
it should work as expected.
🙌 1