Reputation: 3969
Example build.gradle
:
apply plugin: 'com.android.application'
android {
defaultConfig {
applicationId propAppcationId
}
}
My plugin:
public class AudioMaterialAppConstructorPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
Task constructAudioMaterialApp = project
.getTasks()
.create("constructAudioMaterialApp", ConstructAudioMaterialAppTask.class);
project.getTasks().getByName("preBuild").dependsOn(constructAudioMaterialApp);
}
}
My custom task:
public class ConstructAudioMaterialAppTask extends DefaultTask {
@TaskAction
public void constructAudioMaterialApp() {
getProject().setProperty("propAppcationId", "demo.project.id");
}
}
I want to change applicationId
before build task
. As you can see, I tried to do it via property, but it doesn't work. How can I manage this case?
Upvotes: 0
Views: 623
Reputation: 11619
It does not work because config is resolved during configuration phase and task is executed during execution phase (after).
You can add property in plugin apply method as an alternative. I think it should also work in task constructor, but I'm not 100% sure.
Upvotes: 1