This message was deleted.
# community-support
s
This message was deleted.
e
try removing
@Inject constructor()
c
then it tells me the constructor should be annotated with
@Inject
can't tell which way is progress 😛
c
looks like a constructor injection issue - try
abstract class GenerateFederatedGraphqlSchema : Exec() {
e
what is
graphql
in
register()
? if you're not taking any parameters then there shouldn't be any given
c
from a past gist that’s a const string - the task name.
e
ah right, I usually use
registering
which derives the name automatically
👍 1
c
yeah, it's just a string
@Chris Lee that's the remove
@Inject
that I did 😉 it just tells me it should be
annotated with inject
c
that’s not right. with no constructor parameters there’s no need to annotate. Have many custom tasks w/ no constructor params (not even sure how to provide params to inject into the constructor - guess you could do the canned services I suppose).
Copy code
internal abstract class GenerateJarProperties : DefaultTask() {
c
I mean.. idk, but that's the error it gives me
I remove inject, it complains about it not being there, I add it, it gives me this error
c
remove not just the annotation - the bogus, empty
constructor()
c
didn't happen until I added an @TaskAction... and converted those method's to val's
yeah, I did that to 😉
c
the vals are fine.
c
too*
I removed
@Inject constructor()
and then it says inject should be on the constructor
idk
e
ah, figured out what it is
exec
and
file
implicitly capture them from build script scope, which the compiler handles by adding hidden parameters
c
lovely. Looking closer at this - it doesn’t need to subclass Exec, should inject ExecOperations
e
this works (and doesn't require
@Inject constructor()
):
Copy code
@TaskAction
    fun action() {
        workingDir = project.file("../../")
        project.exec {
            commandLine = mutableListOf("yarn", "generate:graphql")
        }
        project.exec {
            commandLine = mutableListOf("yarn", "prettier", "--write", outputSchema.get().asFile.path)
        }
    }
but yeah, as Chris says, it would be better to inject ExecOperations and ProjectLayout, extending DefaultTask, than to use project and Exec
c
Something like this:
Copy code
abstract class GenerateFederatedGraphqlSchema : DefaultTask {
  @get:Inject
  protected abstract val execOps : ExecOperations

  @get:Inject
  protected abstract val layout : ProjectLayout

  @get:SkipWhenEmpty
  @get:InputFiles
  @get:PathSensitive(PathSensitivity.RELATIVE)
  abstract val sourceFiles: ConfigurableFileCollection

  @get:OutputFile
  abstract val outputSchema: RegularFileProperty

  @TaskAction
  fun action() {
    workingDir = layout.projectDirectory.file("../../")
    execOps.exec {
      commandLine = mutableListOf("yarn", "generate:graphql")
    }
    execOps.exec {
      commandLine = mutableListOf("yarn", "prettier", "--write", outputSchema.get().asFile.path)
    }
  }
}
e
you'd have seen the error immediately if this were defined outside of a build script
c
indeed. confused me for a moment seeing a random
file
in a custom task…
c
k, giving it a go...
had to fix a couple of other things along the way, working now, thanks guys
👍 1