Init script for dependency checker

In advance, I really feel stupid for asking this…

Im trying to apply the dependency checker plugin though init-script and for the life of me I cannot figure out where I go wrong. I feel 90% sure that I have a typo somewhere.

Here is what I have attempted so far:

initscript {
    repositories {
        maven { url "https://<internal>" }
    }
    dependencies {
        classpath "org.owasp:dependency-check-gradle:8.2.1"
    }
}

rootProject {
    apply(plugin = "org.owasp.dependencycheck") <-- this is koltlin syntax so that does not work
}

This fails with error:
Could not set unknown property ‘plugin’ for root project ‘<>’ of type org.gradle.api.Project.

So I tested various combos of “apply plugin”:

apply plugin: org.owasp.dependencycheck.DependencyCheckPlugin

result: Could not get unknown property ‘org’ for root project ‘<>’ of type org.gradle.api.Project.

And:

 apply plugin: 'org.owasp.dependencycheck'

Plugin with id ‘org.owasp.dependencycheck’ not found.

I do a very similar thing for sonarqube and that works, and adding a buildscript block in a single project works. That buildscript looks like:

buildscript {
    repositories {
        maven { url artifactory_url+"/all-libs" }
    }
    dependencies {
         classpath 'org.owasp:dependency-check-gradle:8.2.1'
    }
}
apply plugin: 'org.owasp.dependencycheck'

I stared at this for too long now and Im hoping that a fresh pair of eyes will see a really stupid mistake :slight_smile:

The problem of the first snippet you showed is, that you try to use Kotlin DSL syntax in a Groovy DSL init script. So the plugin = ... is not seen as setting a named parameter, but as setting a property of the this object and it complains that it doesn’t find that property.

I think the second snippet should work fine, at least if the class name is correct.
But alternatively try to “import …” the class and use the simple class name with the apply call.

It was me being too tired.

The problem was cause by me failing to write the correct class name.

I wrote:

apply plugin: org.owasp.dependencycheck.DependencyCheckPlugin

I it should be:

apply plugin: org.owasp.dependencycheck.gradle.DependencyCheckPlugin

Thanks for making me look again @Vampire, the “try with import” set me in the right direction

1 Like