gradlekotlindexguard

How to get a custom method inside a block with Kotlin Gradle DSL?


I'm migrating one app from Gradle Groovy to Kotlin. This app uses Dexguard, and it uses a method called getDefaultDexGuardFile to load the configuration file.

release {
  signingConfig signingConfigs.upload
  proguardFiles getDefaultDexGuardFile('dexguard-release-aggressive.pro')
  proguardFiles 'dexguard-rules.pro'
}

But when migrating to Kotlin, I cannot find a way to make it recognize this option:

getByName("release") {
  signingConfig = signingConfigs.getByName("upload")
  proguardFiles(
    "getDefaultDexGuardFile"("dexguard-release-aggressive.pro"), // ?
    getDefaultDexGuardFile("dexguard-release-aggressive.pro"), // ?
    "dexguard-rules.pro",
  )
}

The IDE don't suggests any import, so I don't know how to make it. In the Dexguard's jar, I saw two references of this method:

public class C0867Pp extends Closure implements GeneratedClosure

and

public class C0828PC implements GroovyObject

Solution

  • After playing a bit with the plugin options, I found this solution:

    getByName("release") {
      signingConfig = signingConfigs.getByName("upload")
      proguardFiles(
        extraDexguardMethods.getDefaultDexGuardFile("dexguard-release-aggressive.pro"),
        "dexguard-rules.pro",
      )
    }