pedrovgs / Shot

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

"Unresolved reference: shot" #319

Closed StefanOltmann closed 2 years ago

StefanOltmann commented 2 years ago

I try to figure out where exactly I need to place this in my build.gradle.kts:

shot {
  applicationId = "com.myapp"
}

No matter where I place it, it never compiles.

shen-david commented 2 years ago

+1 no idea what to do here

StefanOltmann commented 2 years ago

@shen-david I gave up trying Shot and use now a simpler approach: https://github.com/googlecodelabs/android-compose-codelabs/blob/main/TestingCodelab/app/src/androidTest/java/com/example/compose/rally/ScreenshotComparator.kt

Only needed a Gradle task to pull the screenshots after that:

project.afterEvaluate {

    val file = File(project.buildDir.absolutePath, "pull_screenshots.sh")

    file.parentFile.mkdirs()

    file.printWriter().use { writer ->
        writer.println(
            "\$ANDROID_HOME/platform-tools/adb pull " +
                "\"/storage/emulated/0/Pictures/.\" " +
                "\"${project.projectDir}/src/androidTest/assets\""
        )
    }

    file.setExecutable(true)
}

tasks.register<Exec>("pullFilesTask") {

    val file = File(project.buildDir.absolutePath, "pull_screenshots.sh")

    commandLine("$file")
}

val pullFilesTask: Task by tasks.getting

// Finalize test task by pulling the files
tasks.withType<com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask> {
    this.finalizedBy(pullFilesTask)
}

I would have preferred using Shot, but I did not manage to get it working and nobody responded to my issue. So I decided that I don't need it.

Hope that helps you.

oluwafemi-bamisaye commented 2 years ago

Hi @StefanOltmann and @shen-david, I was able to resolve this problem.

Removing this line: apply(plugin = "shot")

and adding "shot" to the plugins block like below fixed it for me:

plugins {
    ..... // my other plugins
    kotlin("kapt")
    id("shot")
}

Then I could use the shot extension in the build.gradle.kts like this:

shot {
  applicationId = "com.myapp"
}

Don't forget to also add the class path dependency: classpath 'com.karumi:shot:' as recommended in the Getting started

shen-david commented 2 years ago

thanks @oluwafemi-bamisaye! However, I actually still understand how this works - could you please paste your buildscript and pluginManagement block? I still get the following, which suggests this doesn't work because this shot lib isn't here. Screen Shot 2022-10-10 at 12 41 41 PM

Here's a snip from my build.gradle.kts, which produces above

buildscript {
    repositories {
        maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
        mavenCentral()
        maven { url = uri("https://maven.google.com") }
        google()
        gradlePluginPortal()
    }

    dependencies {
        classpath("com.karumi:shot:5.14.0")
    }
}

plugins {
 id("shot")
 }

from settings.gradle.kts

// this block declares where to find the plugins used across all subprojects
pluginManagement {
    // Get community plugins from the Gradle Plugin Portal
    repositories.gradlePluginPortal()
    // And Android plugins from Google
    repositories.google()
    // And maven central
    repositories.mavenCentral()
    repositories.maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}
shen-david commented 2 years ago

ok, the issue was that my

dependencies {
        classpath("com.karumi:shot:5.14.0")
    }

block was in the same module-level build.gradle.kts file - i moved it to the top-level build.gradle.kts file, and then the extension resolved correctly!

Venkat-juju commented 1 year ago

I'm getting Plugin not found exception with the new method of applying plugins while gradle sync:

Issue image

my settings.gradle file:


pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    plugins {
        ... some other plugins....
        id 'shot' version '5.14.1'
    }
}

my module level build.gradle file:


plugins {
    id 'shot'
}

I'm not sure if this is the issue with my configuration or plugin side issue. but it works fine for other plugins. Kindly help!