Gradle buildSrc and buildscript

We have a Gradle assembly that includes buildSrc with some custom plugins. These plugins also use other plugins. For example, our plugin uses com.android.tools.build:gradle . To compile annotations during compilation, the library must be in the Gradle classpath. So, putting this in our main build.gradle works:

 buildscript { repositories { google() } dependencies { classpath "com.android.tools.build:gradle:$gToolsVersion" } } 

However, this means that for the user to apply this plugin, they must (1) apply our plugin and (2) add that buildscript template. This does not seem to be necessary. We can also add the project.buildscript block inside our plugin, but this also seems unnecessary and is problematic because of this error: https://developer.android.com/studio/build/gradle-plugin-3-0-0.html ? utm_source = android-studio # known_issues .

I added the com.android.tools.build:gradle dependency to buildSrc/build.gradle as a runtime dependency. This seems to work: I thought Gradle was saying that to run my plugin this library (and its dependencies) should be in the classpath. However, gradle buildEnvironment (and the fact that our assembly fails) makes it clear that this is not the case.

So the questions are:

  • What is the difference between the runtime dependencies specified in buildSrc/build.gradle and the classpath dependencies specified in the buildscript block in the regular build.gradle file?
  • How can I arrange things so that users can use the buildSrc and not have to add the buildscript block to their build.gradle as build.gradle ?
+5
source share

Source: https://habr.com/ru/post/1273848/


All Articles