This message was deleted.
# community-support
s
This message was deleted.
v
Which part are you struggling with? You basically just implement the
ValueSource
interface and then use for example
providers.of<YourValuSourceClass>() { ... }
to create a provider that uses it and wire that to the task property.
But I have no concrete example at hand, sorry
c
Yeah I don't exactly understand how the wiring works. I can show you what i have so far
I created ValueSources that return a Java Bean or a String which work fine
Then i hava a task with several @Input, so far i have used Strings as in
Copy code
@Input
public abstract Property<String> getGitVersionCmd();

@Input
public abstract Property<String> getHash();
these are declared in my task, that extends DefaultTask
Should i declare
Copy code
@Input
public abstract MyValueSource getMyValueSource();
and then, how to use that in my build.gradle?
I've tried stuff like
Copy code
def 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
}
but that doesn't seem correct
And now i'm a bit stuck
Also what I did it looks overly complicated, if the valuesource itself has parameters
v
The value source has a type parameter what it produces, for example
String
. 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.
So basically what you tried from a cursory look
šŸ‘ 1
c
So the "wiring" of the ValueSource to the string property is actually done in build.gradle? And i have to "reconfigure" the task to do this?
v
I'm not sure what you mean. Typically such wirings are done in plugins, but you also do them in build scripts directly.
c
I'm not native english, let me try to rephrase What i expect is that i can do almost everything in the plugin setup where i register the task itself. But i haven't understood so far how to do this in java in the plugin (providing a possibility to overwrite the parameters of the valuesource), so i did that in the build.gradle
my task has to accept two parameters: • a string to a git dir • a string to a cmd line tool (used by the valuesource)
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?
v
I'm not native english
Me 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.
c
let me try that
Got it working after some fiddling. Basically i now created several tasks, that build on each other I set the parameters for the valuesource with the input parameters of the task that uses the valuesource to compute another input
Copy code
final 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)
                            )
                    )));
					...
                }
        );
Not sure that is the best solution, but it works fine
v
Seems fine from a cursory look
šŸ‘ 1