I have created a custom gradle plugin - TaskConfigPlugin
Gradle Version: 1.12/2.0
(Can’t upgrade as of now due to Org restrictions)
Java Version: 1.8
My Plugin code is as follows - TaskConfigPlugin.java
>>
public class TaskConfigPlugin implements Plugin<Project> {
private String taskPrefix;
private Task mainTask;
@Override
public void apply(Project project) {
TaskConfigPluginExtension extension = project.getExtensions()
.create("taskOrder", TaskConfigPluginExtension.class);
this.taskPrefix = extension.getTaskPrefix(); //the taskPrefix fetched is null
this.mainTask = extension.getMainTask(); //mainTask fetched is null
configureTaskOrdering(project);
}
private void configureTaskOrdering(Project project){
// My Logic to order the task using 'dependsOn', 'mustRunAfter' etc
// It uses the 'taskPrefix' to fetch all matching tasks and then
// establish the relationship with the 'mainTask'
}
}
The extension object - TaskConfigPluginExtension.java
>>
public class TaskConfigPluginExtension {
private String taskPrefix;
private Task mainTask;
// getters and setters for the above
}
I have added the plugin info in the META-INF/gradle-plugins/TaskConfigPlugin.properties
which contains the full package name of the Plugin.
The plugin is being consumed as follows in my gradle - mainConsumer.gradle
buildscript {
repositories {
flatDir name: 'libs', dirs: 'lib/'
}
dependencies {
classpath ':TaskConfigPlugin:1.0'
}
}
apply plugin: 'TaskConfigPlugin'
task mainConsumer
taskOrder {
taskPrefix = 'setup'
mainTask = mainConsumer
}
Now when I run my consuming gradle mainConsumer.gradle
, I see that the taskPrefix
and mainTask
values fetched are NULL. I understand that they belong to the CONFIGURATION
phase and hence the values cannot be fetched earlier. But I tried with the project.afterEvaluate
option and that is also NOT working for me.
There are some solutions (hoping they work) in terms of Provider
and Property
but I can’t use them since they have been introduced with higher gradle versions, I guess 4.+
So, is there some solution or workaround for me with gradle 1.12
to fetch the extension values in the CONFIGURATION
phase itself ?
Appreciate your response. Thanks in advance.