Slackbot
09/11/2023, 9:09 AMVampire
09/11/2023, 9:30 AMValueSource interface and then use for example providers.of<YourValuSourceClass>() { ... } to create a provider that uses it and wire that to the task property.Vampire
09/11/2023, 9:31 AMChristoph Hermann
09/11/2023, 9:59 AMChristoph Hermann
09/11/2023, 10:00 AMChristoph Hermann
09/11/2023, 10:01 AM@Input
public abstract Property<String> getGitVersionCmd();
@Input
public abstract Property<String> getHash();Christoph Hermann
09/11/2023, 10:01 AMChristoph Hermann
09/11/2023, 10:03 AM@Input
public abstract MyValueSource getMyValueSource();Christoph Hermann
09/11/2023, 10:03 AMChristoph Hermann
09/11/2023, 10:04 AMdef hashProvider = providers.of(MyValueSource.class, spec -> {
spec.getParameters().getGitDir().set(project.projectDir.getParentFile().getParentFile().getParentFile().getAbsolutePath())
})
tasks.findByName("myTask").configure {
gitVersionWorkingDir = project.projectDir.getAbsolutePath()
hash = hashProvider
}Christoph Hermann
09/11/2023, 10:04 AMChristoph Hermann
09/11/2023, 10:04 AMChristoph Hermann
09/11/2023, 10:15 AMVampire
09/11/2023, 10:43 AMString.
When you use providers.of<MyValueSoruce> { ... } what you get in return is a Provider<String>.
In the task you have a Property<String> and then you just do thePropertyInTheTask = theProviderYouGot and everything should work.Vampire
09/11/2023, 10:44 AMChristoph Hermann
09/11/2023, 11:41 AMVampire
09/11/2023, 11:48 AMChristoph Hermann
09/11/2023, 11:52 AMChristoph Hermann
09/11/2023, 11:53 AMChristoph Hermann
09/11/2023, 11:58 AMVampire
09/11/2023, 12:00 PMI'm not native englishMe neither. Actually I'm not too far away and next week will even be around the corner (Haslach). š
So what i would try is to wire a property of the task to the property of the value source in the register() call and then just set properties on the task?Never tried it like that, but should probably work, yes.
Christoph Hermann
09/11/2023, 12:01 PMChristoph Hermann
09/11/2023, 5:11 PMChristoph Hermann
09/11/2023, 5:14 PMfinal String extensionDir = myExtension.getDir().getOrElse(project.getProjectDir().getParentFile().getParentFile().getParentFile().getAbsolutePath());
TaskProvider<MyTask> myTaskTaskProvider = project.getTasks().register("my", MyTask.class);
myTaskTaskProvider.configure(
action -> {
action.getHash().set(project.getProviders().of(MyValueSource.class, conf -> conf.parameters(
valueSourceParameters -> valueSourceParameters.getDir().set(
action.getDir().orElse(extensionDir)
)
)));
...
}
);Christoph Hermann
09/11/2023, 5:16 PMVampire
09/11/2023, 6:46 PM