Porting to Kotlin DSL: groovy extension doesn't work

(Vlad Svoka) #1

Hello!
I’m trying to port very large and complex build script from groovy to Kotlin DSL. I hit a roadblock, because groovy uses https://github.com/michel-kraemer/gradle-download-task to download some 3rd party plugins. Download process is complex, and could not be performed on configuration stage, only when building stuff.
Groovy code looks something like this:

task downloadPlugins << {
    pluginsToDownload.each {
        download {
        {
            src it
            dest buildDir
        }
    }
}

My KTS task looks like this, but doesn’t work

tasks.create("downloadPlugins") {
    val pluginUrls = listOf("https://google.com")
    doLast {
        pluginUrls.forEach{ pluginUrl ->
             /* this bit doesn't work: */
             download {
                 src(pluginUrl)
                 dest("$buildDir/downloadedPlugins/extension")
             }
        }
    }
}

This fails on configuration with following error:

Unresolved reference: src
Unresolved reference: dest

Also, if I create a task with Download type, it works just fine.
I created a repo with working code, and code which I want to work is commented out: https://github.com/Shchvova/GradleDSLDownloadPlugins/blob/master/build.gradle.kts

(Vlad Svoka) #2

After some digging I gave up and realized that I can do it like this:

    DownloadAction(project).apply {
        src(pluginUrl)
        dest("$buildDir/downloadedPlugins/extension")
    }.execute()

Ugly, but does job done.