Configure an external plug-in from my own custom Java plug-in

Hi,

We are currently making the step to set some company-wide conventions/standards.
We would like to use them to simplify configuring our Gradle-based projects, by introducing a plug-in (written in Java), that contains these conventions and applies them to the project based on a minimal set of configuration parameters.

I’ve already managed to add one of the plugins we would like to depend on, by using:

public class MyPlugin implements Plugin<Project> {

  public void apply(Project project)
  {
    project.getPlugins().apply(ExternalPlugin.class);
  }
}

This works. I can see the tasks added by ExternalPlugin.
However, how can I configure this plugin?

For now I’m using settings.gradle to provide the input for the configuration, as I can read this while I’m in the apply() method (and the configuration I can define in build.gradle for the plug-in using Extensions, is not).
Is there a way to add and configure other plug-ins after reading the configuration based on my plugins extension?

In short: How can I configure another plug-in using an instance of Project in Java?
(How) can I do this after the configuration in build.gradle is loaded?

Hopefully someone can help me.

Thanks,
Arno

I’m not sure to understand your question, but the afterEvaluate hook is designed for that.

Note that the new model will allow more subtle things regarding the configuration phase

@Francois_Guillot That sounds about right. Will check it soon.

I currently managed to configure the plugins by either using their own provided extension and adding/extracting that from project.getExtensions() or creating a local class that represents their custom DSL within an “extension” class.

I am currently struggling to load a file I have included in my plugins resources.

URL urlForResource = project.getBuildscript().getClassLoader().getResource(resourceName);
File f = project.file(urlForResource);

The call to getResource() seems to return a perfectly fine URL for the resource within the JAR.
The call to project.file() results in a InvalidUserDataException stating that it cannot convert the URL 'jar:file:/path/to/jar!/resource.file` to a file.
Any ideas on how to load the resource from the jar and use it within the project configuration?

You can load the resource as a stream and then write it to a file if you really need to