Hi
I’ve been using Gradle some weeks, and I’m now trying to create my own plugin. I have several microservices, and I want to create one plugin that import in all my microservices, so that I can share common things needed by each microservice’s build. Currently I want to do two things, and that is run the gradle application plugin’s task “installDist”, and then the task Copy (in order to create an executable of my project, then copy it to somewhere specific for later use in my CI.)
Problem:
I don’t know how, or if it’s possible, to set the application plugin’s property “mainClassName”, from my custom plugin.
My plugin’s code:
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.ApplicationPlugin;
public class GreetingPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getExtensions().create("distConfig", DistConfig.class);
project.getPlugins().apply(ApplicationPlugin.class);
// How can I execute application plugin's task installDist, with mainClassName set?
}
}
public class DistConfig {
public String main;
}
Workaround:
I am able to set the mainClassName the following way:
apply plugin: 'com.yngvark.gridwalls.common_build_plugin'
distConfig {
main = 'mytest.Main'
}
mainClassName = 'mytest.Main' // They did it like this in https://github.com/ratpack/example-ratpack-gradle-java-app/blob/master/build.gradle
However, I believe this is not the best design, as it makes details of the application plugin leak through to my microservices. I only want the properties of my CommonBuildPlugin to be visible to my microservices.
By the way, I have read Configuring a plugin programmatically using extension variables , and while they recommend to go with the new @Model approach, I am right now just wondering if it’s possible at all do what I’m asking above.