Search code examples
androidgradlekotlindynatrace

Configuration of Dynatrace in Gradle Kotlin DSL


I have an Android project, using a Gradle build configuration written in the kotlin-dsl and trying to apply Dynatrace:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath("com.dynatrace.tools:android:7.2.4.1262")
  }
}

// I apply the plugin
apply(plugin = "com.dynatrace.tools.android")

Everything runs smoothly until I try to use the dynatrace configuration block, which is never resolved:

dynatrace {
    defaultConfig {
       ....
    }
}

This is the environment I am working with:

  • Gradle: 5.1.1
  • Android Gradle plugin: 3.4.1
  • Dynatrace version: 7.2.4.1262

I am following Dynatrace's own instructions, and even though they don't mention how to perform the configuration with the kotlin-dsl, they have just added support for it.

Any help would be appreciated.


Solution

  • I have tried it with the apply DSL and it didn't work. I got it working applying the plugin via plugins DSL.

    Top level build.gradle.kts:

    buildscript {
        repositories {
            google()
            jcenter()
    
        }
        dependencies {
            classpath("com.android.tools.build:gradle:3.5.0-beta01")
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
            classpath("com.dynatrace.tools:android:7.2.4.1262")
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()  
        }
    }
    

    App build.gradle.kts:

    plugins {
        id("com.android.application")
        kotlin("android")
        id("com.dynatrace.tools.android")
        ...
    }
    
    android {
        defaultConfig {
            ...
        }
        buildTypes {
            ...
        }
    }
    
    dynatrace {
        defaultConfig {
            ...
        }
    }
    
    dependencies {
        ...
    }