How to execute "./gradlew build --refresh-dependencies" from gradle plugin

101 views Asked by At

I'm trying to write my own gradle plugin in Kotlin. It executes fine, but I want the build task to be run with --refresh-dependencies argument, such that the final outcome is the equivalent of

./gradlew build --refresh-dependencies
./gradlew publishToMavenLocal

Here is my custom plugin:

class PublishManager : Plugin<Project> {
    override fun apply(target: Project) {
        target.task("syncAndPublish") {
            doLast {}
        }.dependsOn("publishToMavenLocal")
         .dependsOn("build") // HOW TO ADD -refresh-dependencies HERE?
    }
}
1

There are 1 answers

0
GreenSaguaro On BEST ANSWER

Try this in your plugin:

target.gradle.beforeProject {
    gradle.startParameter.isRefreshDependencies = true
}