https://kotlinlang.org logo
Title
a

arnaud.giuliani

02/22/2020, 9:53 AM
Hi all, I’ve got a gradle task that I would like to distribute. It’s just a task that allow to run a category of test:
task checkModules(type: Test) {
    testLogging {
        showStandardStreams = true
    }
    useJUnit {
        includeCategories 'org.koin.test.category.CheckModuleTest'
    }
}
It’s for a library. Can I distribute it as a Gradle plugin?
m

mbonnin

02/22/2020, 9:55 AM
You mean put it on the Gradle Plugin Portal ? Of course but you'll have to package it as a jar, give it a plugin id, etc, there's some boilerplate
a

arnaud.giuliani

02/22/2020, 9:57 AM
yes, but that’s ok. I want to allow to run easily this CheckModuleTest category without asking users to write this task
m

mbonnin

02/22/2020, 9:58 AM
This page says you can do it in 12 minutes 🙂 https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/
a

arnaud.giuliani

02/22/2020, 10:01 AM
cool, thanks
and then I need to make a Gradle plugin project?
(to export it as a jar)
m

mbonnin

02/22/2020, 10:03 AM
Yes, you'll need a complete gradle project (hence the boilerplate) which applies these plugins:
plugins {
    id 'java-gradle-plugin' 
    id 'com.gradle.plugin-publish' version '0.10.1' 
}
The
java-gradle-plugin
will generate the jar and
com.gradle.plugin-publish
will handle publication
Alternatively, you could just host your snippet as a gist and tell users to
apply(from = check-modules-task.build.gradle)
For just a few lines, that might be easier
a

arnaud.giuliani

02/22/2020, 10:06 AM
this is for a library, will be better to have the complete stuff then 🙂
The task I have written above can be exported with this kind of stuff then? https://docs.gradle.org/current/userguide/custom_plugins.html
m

mbonnin

02/22/2020, 10:08 AM
If you want full plugin support, that's the "A standalone project" section in this link
a

arnaud.giuliani

02/22/2020, 10:09 AM
ok, thanks 👍
m

mbonnin

02/22/2020, 10:11 AM
I was just checking and apparently, users can also apply plugins from a url so if you were to host your snippet on github, you could just ask your users to do
apply(from: uri("<https://raw.github.com/username/check-modules-gradle>"))
I think that would work and would be much faster.
But the "standalone project" will give you full flexibility
a

arnaud.giuliani

02/22/2020, 10:13 AM
yeah, this is a convenient way to go fast 🙂
or even host this snippet on a website? like
apply(from: uri("<https://insert-koin.io/check-modules-gradle>"))
👍 1
could be interesting 👍
even if the state of the art would suggest to have a standalone plugin project 😛
thanks for your answers
👍 1
m

mbonnin

02/22/2020, 10:16 AM
Yep, I've never done it but documentation says that that other schemes that file:// are supported.