0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I used plugin's apply method and it works: @Override public void apply(Project project) { project.setProperty("propAppcationId", "demo.project.id"); }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.