title: Gradle Kotlin DSL unresolved references defined in buildSrc
body: <p>I'm experimenting with Kotlin DSL but I can't get it to recognize objects I defined in buildSrc. They get resolved by the IDE but when I compile the code it doesn't work.</p>
  <p>This is the my project structure:</p>
  <pre><code>build.gradle.kts
  settings.gradle.kts
  +buildSrc
      build.gradle.kts
      +src
          +main
              +java
                  Dependencies.kt
                  Versions.kt
  +module1
      build.gradle.kts
  +module2
      build.gradle.kts
      
  </code></pre>
  <p>Content of Dependencies.kt:</p>
  <pre><code>/**
   * To define plugins
   */
  object BuildPlugins {
      val gradle by lazy { &quot;com.android.tools.build:gradle:${Versions.gradlePlugin}&quot; }
      val kotlinGradle by lazy { &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}&quot; }
      val safeArgs by lazy { &quot;androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.safeArgs}&quot; }
  }
  
  /**
   * To define dependencies
   */
  object Deps {
      val appCompat by lazy { &quot;androidx.appcompat:appcompat:${Versions.appCompat}&quot; }
      val core by lazy { &quot;androidx.core:core-ktx:${Versions.core}&quot; }
      val timber by lazy { &quot;com.jakewharton.timber:timber:${Versions.timber}&quot; }
      val kotlin by lazy { &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}&quot; }
      val material by lazy { &quot;com.google.android.material:material:${Versions.material}&quot; }
      val constraintLayout by lazy { &quot;androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}&quot; }
  }
  
  </code></pre>
  <p>Project wide build.gradle.kts (the one which fails first):</p>
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  buildscript {
      repositories {
          google()
          mavenCentral()
      }
      dependencies {
          BuildPlugins.gradle
          BuildPlugins.kotlinGradle
          BuildPlugins.safeArgs
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  ...
  </code></pre>
  <p>I also want to point out that the android { ... } block is not recognized in the modules gradle files but I think that may be because of the failed compilation.</p>