How to apply a plugin from outside a build script?


(steve) #1

I have looked at other “similar” posts such as http://forums.gradle.org/gradle/topics/best_approach_to_apply_custom_plugin_to_root_project_via_init_script_in_a_custom_distribution and http://forums.gradle.org/gradle/topics/how_can_you_use_an_init_script_to_specify_a_repo_dependency_for_a_plugin_jar_but_allow_version_to 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 (https://github.com/hibernate/hibernate-matrix-testing 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?


(Luke Daley) #2

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


(steve) #3

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

allprojects {
    apply "the-plugin";
}

(Luke Daley) #4

Yes, this is the API: http://www.gradle.org/docs/current/dsl/org.gradle.api.invocation.Gradle.html

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.