11

I use Gradle Kotlin DSL and in my project I have separate build-dependencies gradle module which is included in settings.gradle.kts like so:

pluginManagement {
    repositories {
        google()
        jcenter()
        gradlePluginPortal()
    }
}

includeBuild("build-dependencies")

This module contains empty plugin implementation and Deps object. Its build.gradle.kts below:

repositories {
    google()
    jcenter()
    gradlePluginPortal()
}

plugins {
    `kotlin-dsl`
    `java-gradle-plugin`
}

gradlePlugin {
  plugins.register("com.example.dependencies") {
      id = "com.example.dependencies"
      implementationClass = "com.example.dependencies.DependenciesPlugin"
  }
}

Deps object:

object Deps {
  const val buildTools = "com.android.tools.build:gradle:4.1.1"
  // more dependencies
}

I want to use this Deps object in all modules by applying the plugin in build.gradle.kts files.

plugins {
  id("com.example.dependencies")
}

And it works fine, I can import and use Deps object.

But there is a problem when I want to use it in root projects build.gradle.kts and more precisely in buildscript like so:

buildscript {
    repositories {
        google()
        jcenter()
    }

    plugins {
        id("com.example.dependencies")
    }

    dependencies {
        classpath(com.example.dependencies.Deps.buildTools) // It doesn't work
    }
}

Is there any way to use a custom plugin inside buildscript like this or could you suggest something to replace this approach?

pavelkorolevxyz
  • 1,380
  • 2
  • 14
  • 35

0 Answers0