Apply buildscript from a common gradle file

I am writing my own plugins to extend gradle, those plugins are separated in different jars. In order for user to use my plugins, they need to adding following to their build.gradle file:

buildscript {
    repositories {
        ivy {
           ivyPattern '...'
           artifactsPattern '...'
        }
    }
    dependencies {
        compile group:'myorg', name: 'mymodule', version: '1.0'
        compile group:'myorg', name: 'mymodule2', version: '1.0'
    }
}
  apply plugin: 'myplugin1'

Which is quite tedious, I want to put this buildscript section in a common gradle file, and my user only need to apply from: common.gradle to have it set up.

But seems a buildscript section in a common.gradle doesn’t apply to the target build.gradle file, the closest I can get is:

buildscript {
    apply from: common.gradle, to: buildscript
}

But what I want in this common.gradle file is not only setup buildscript, but also some other common settings, so the ideal is:

apply from: common.gradle

Which applies both the buildscript setup and some other common settings to the project. Is there a way to achieve so?

Currently the ‘buildscript’ block is simply needed. It’s the same for every third-party plugin, and it’s not worth the hassle to try and work around it. We are working on a better solution.

PS: In the ‘buildscript’ block it’s ‘dependencies { classpath … }’, not ‘dependencies { compile … }’.

Thanks Peter, as to the better solution, could you explain what would it looks like, and is there a rough estimation on its arrival?

1 Like

I don’t have any detail information.

The only way to inject into the ‘buildscript {}’ for projects is to use an Init script.

http://www.gradle.org/docs/current/userguide/init_scripts.html