How to apply a plugin from outside a build script?

I have looked at other “similar” posts such as and but they all seem a bit different.

The situation I have is this… Hibernate needs to be testable against any number of different databases. To support this, I developed a “matrix testing plugin” which allows the checkout environement to define a set of “database profiles” and dynamically set up test tasks for running the tests against those profiles ( if you are interested in the specifics).

Red Hat, as a company, wants to run those tests against a certain set of these database profiles. That part is fine. The Hibernate build already applies the hibernate-matrix-testing plugin and the Red Hat QA CI environment defines the database profiles it needs. So far so good. However, part of running those tests in the Red Hat CI environment is the need to allocating/de-allocating database instance (very much like a cloud service). This allocating/de-allocating service is available through a Servlet called DatabaseAllocator. I need to be able to hook in calls to the DatabaseAllocator as part of the running of the related matrix test tasks. So when the matrix test task for the ‘oracle10g’ database profile runs we need to manage the allocation of an Oracle 10g database instance through the DatabaseAllocator service.

Initially I had planned on accomplishing this by writing a DatabaseAllocator Gradle plugin and BuildListeber that would essentially manage the allocation/de-allocation. But I have no idea how to apply that to the build from outside the build script. I don’t want the Hibernate build script to have to account for this. I’d prefer the handling of this to be local to the CI checkout of the project. Is that in any way possible? Any suggestions?

You’d use an init script, applied via the -I command line option… if I understand you correctly.

To make sure I understand correctly, something like this in an “init script”?

allprojects {
    apply "the-plugin";

Yes, this is the API:

Be aware though, there are issues around applying plugins to projects from init scripts. I suspect you are going to hit GRADLE-2407.

One thing you could try is applying a script plugin from the init script, and in this script plugin apply your binary plugin.

This will workaround the callback ordering bug that effectively is GRADLE-2407.