snyk / gradle-plugin

Snyk Gradle Plugin - Scanning and monitoring your dependencies for security vulnerabilities from Gradle
Other
20 stars 19 forks source link

Running `snyk code test`? #21

Open vnickolov opened 2 years ago

vnickolov commented 2 years ago

Hello 👋

Is there a way to configure the plugin to run equivalent of snyk code test which is the command for scanning the code under development rather than its depencencies?

So far we've achieved this by adding a handcrafted task, but we think it's more hack than a solution.

tasks.register('snyk-code-test', Exec) {
    dependsOn ':snyk-check-binary'

    workingDir rootProject.projectDir

    commandLine 'snyk', 'code', 'test'
}

Thank you in advance, Ves

Direwolfik commented 1 year ago

To anyone it might concern - it might be a bit better to run it like this

    open class SnykCodeTask : SnykTask() {
        @TaskAction
        fun doCodeTestTask() {
            log.debug("Snyk Test Task")
            authentication()

            val output = runSnykCommand("code test")
            log.lifecycle(output.output)

            if (output.exitcode > 0) {
                throw GradleException("Snyk Test failed")
            }
        }
    }

    tasks.register<SnykCodeTask>("snyk-code-test")

this utilizes functions available in parent SnykTask and correctly propagates all arguments provided in snyk block.

Anyway I agree that it would be nice to have it supported out of the box.