Slackbot
05/12/2022, 8:10 AMCristianGM
05/12/2022, 8:11 AMjmfayard
05/12/2022, 8:14 AMabstract class AddTask @Inject constructor(
@get:Input val projectLayout: ProjectLayout
) : DefaultTask() {Vampire
05/12/2022, 9:32 AMrootdir from the script object, so the AddTask class got automatically a parameter to receive a reference to the enclosing object. And then Gradle couldn't instantiate it and suggested to annotate it with @Inject which actually wouldn't have helped in that situation.
By using the injected project layout you do no longer reference the enclosing object and so no extra parameter is added to the constructor.jmfayard
05/12/2022, 9:48 AMJavi
05/12/2022, 10:23 AMjmfayard
05/12/2022, 10:24 AMval file = projectLayout.projectDirectory.file("some/path").asFileVampire
05/12/2022, 10:24 AMJavi
05/12/2022, 10:26 AMVampire
05/12/2022, 10:27 AMprojectDir or file("xxx") and for that ProjectLayout is perfectly fine.
Just the code example used rootDir which of course is only the same if you are in the root project.Vampire
05/12/2022, 10:28 AMjmfayard
05/12/2022, 10:32 AMJavi
05/12/2022, 10:42 AMThomas Broyer
05/12/2022, 11:02 AMgetProject() too, so:
tasks.register<AddTask>("add")
abstract class AddTask : DefaultTask() {
@TaskAction fun test() = println(this.project.rootDir)
}Javi
05/12/2022, 11:20 AMVampire
05/12/2022, 11:20 AMThomas Broyer
05/12/2022, 11:26 AM