Continuing the discussion from Establishing task dependencies in a plugin:
The solution finally arrived at in the linked task did cause something my earlier version did successfully to break. That was a way of configuring my plugin.
I defined the following java enum type:
public enum WarContainerType {
TOMCAT, WEBLOGIC;
public String getDfltDeplDir() {
switch (this) {
case TOMCAT:
return "webapps";
case WEBLOGIC:
return "web-apps";
default:
//gotta keep compiler happy even if this can't happen.
throw new IllegalArgumentException();
}
}
}
And a little groovy “extension” class:
class ContainerExtension {
@Input @Optional
WarContainerType container = WarContainerType.TOMCAT
}
Then in the plugin apply method, we had
void apply(Project project) {
project.plugins.apply('war')
project.plugins.apply(RpmPlugin.class)
project.extensions.create("dest", ContainerExtension)
Then in the build script, I had
apply plugin: 'vt.content.rpm'
defaultTasks 'rpm'
dest {
container WEBLOGIC
}
dependencies {
providedCompile "javax.servlet:servlet-api:2.2"
}
task rpm(type: RpmContent) {
packageDescription 'gvp008 app - content file installer.'
}
And my little configuration worked, with a WEBLOGIC rather than the default TOMCAT being assumed.
However, the previous solution was to instantiate the tasks in the plugin as the plugin was being applied, rather than in the build script as here.So now we have just
apply plugin: 'vt.content.rpm'
defaultTasks 'rpm'
dest {
container WEBLOGIC
}
dependencies {
providedCompile "javax.servlet:servlet-api:2.2"
compile "com.att.vtone:ivsslib:12.0:jdk1.5"
compile "apache-log4j:log4j:1.2.14"
}
in our buildscript, and our configuration is ignored, with the default TOMCAT being assumed. This is because the task is already created at this point.
What I really want to do is configure this value as the plugin is being applied.
What is the right way to do this? An example of plugin configuration would be appreciated. In looking over the documentation, what looks like it might be helpful is an example of calling the apply method with a map, with that map having both “plugin” and “to” parameters.