pedrovgs / Shot

Screenshot testing library for Android
Apache License 2.0
1.19k stars 116 forks source link

Support for Gradle Kotlin DSL #355

Open maksym-moroz opened 8 months ago

maksym-moroz commented 8 months ago

Expected behaviour

Shot is the last plugin on our project that is not providing a way to use a new plugins block and alias. It would be nice if it was fixed

Actual behaviour

Right now the only way I found is via classpath. Surely there is a lengthy workaround to overcome this by copying everything manually but I feel like Kotlin DSL is the staple for Gradle and Shot snould provide this out of the box

Steps to reproduce

Try to add Shot

Version of the library

Any

NinoDLC commented 4 months ago

FYI, this is the kind of API I expect to add this plugin to my codebase : https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block

ArkeshGKalathiya commented 1 week ago

Here is the way I was able to add it in my project ( Haven't tested it if this works, but I was able to do gradle sync successfully )

CREDIT GOES TO : https://www.caravellecode.fr/android-gradle-plugin-resolution/

settings.gradle.kts

pluginManagement {
    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
    ##### ADDED THIS SECTION #####
    resolutionStrategy{
        eachPlugin{
            when(requested.id.id){
                "shot" -> {
                    useModule("com.karumi:shot:${requested.version}")
                }
            }
        }
    }
}

libs.versions.toml

[versions]
shot="6.0.0"

## make sure id is "shot", I set it "com.karumi.shot" first time, but id from resolved repo ( i.e "shot" ) did not match with the "com.karumi.shot"
[plugins]
shot = { id="shot", version.ref="shot" }

Project level build.gradle.kts

plugins {
    ## not sure why I have done this, but assumed from other integrations ( my 1st week in native android development )
    alias(libs.plugins.shot) apply false
}

app/module level build.gradle.kts

plugins {
    alias(libs.plugins.shot)
}