Convert groovy to kotlin dsl

591 Views Asked by At

Hi everyone I use appDynamics library and the documentation only explains with groovy Gradle, I have a problem with converting the groovy Gradle script to kotlin Gradle DSL and I have tried several ways and several syntaxes and I even used converting tools from groovy to Kotlin Gradle also didn't solve the problem following script with groovy Gradle

adeum {
    
    account {
        name 'xxx'
        licenseKey 'yyyy'
    }
    proguardMappingFileUpload {
        failBuildOnUploadFailure true //should build fail if upload fails? Defaults to false.
        enabled true //enables automatic uploads. Defaults to true.
    }
}

[Error][1] [1]: https://i.stack.imgur.com/tet7q.png

and also i have to mention that the groovy is working fine

2

There are 2 best solutions below

0
shehab osama On BEST ANSWER

The problem is in some plugins in kts you have to use closure to determine the plugin packages

 adeum {
           account(closureOf<com.appdynamics.android.gradle.ADPluginExtension.Account> {
            this.name ="xxx"
            this.licenseKey ="yyy"
    
        })
        proguardMappingFileUpload(closureOf<com.appdynamics.android.gradle.ADPluginExtension.ProguardConfig> {
            this.failBuildOnUploadFailure = true
            this.enabled = true
        })
    }
0
Luiz Tadeu On

It's possible to change adeum to configure<ADPluginExtension>, like this:

configure<ADPluginExtension> {
           account(closureOf<com.appdynamics.android.gradle.ADPluginExtension.Account> {
            this.name ="xxx"
            this.licenseKey ="yyy"
    
        })
        proguardMappingFileUpload(closureOf<com.appdynamics.android.gradle.ADPluginExtension.ProguardConfig> {
            this.failBuildOnUploadFailure = true
            this.enabled = true
        })
    }

I had some issues, when used adeum plugin with kotlin-dsl, where gradle sync not generated extensions accessors to android, dependencies, implementation, etc... provided from kotlin-dsl plugin.