I know gradle has a system for not re-running task...
# community-support
b
I know gradle has a system for not re-running tasks if input files haven't changed, but how do I do that for a custom task? like run "yarn run build" only if files in src/js/ haven't changed?
1
j
When you create a custom task you can set what are the inputs of that task
b
thank you
regarding the exec task, what I'm a looking for? https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html
j
Do you mean you want to implement a custom task that uses Exec?
In that case you can inject
ExecOperations
via constructor
b
do I need a custom task in buildSrc? currently I'm defining it like this
Copy code
tasks.register<Exec>("compileOldJs") {
    workingDir = layout.projectDirectory.dir("oldsrc/").asFile
    commandLine = listOf("yarn", "run", "build")
}
s
you can use
inputs
and
outputs
inside the definition to configure inputs and outputs.
j
Another option you can use the Node Gradle plugin • https://github.com/node-gradle/gradle-node-plugin
b
looks like they're using
Copy code
task buildAngularApp(type: NpxTask) {
  dependsOn npmInstall
  command = 'ng'
  args = ['build', '--prod']
  inputs.files('package.json', 'package-lock.json', 'angular.json', 'tsconfig.json', 'tsconfig.app.json')
  inputs.dir('src')
  inputs.dir(fileTree("node_modules").exclude(".cache"))
  outputs.dir('dist')
}
however this is re-run every time:
Copy code
tasks.register<Exec>("compileOldJs") {
    inputs.dir(fileTree("./oldsrc/src/"))
    workingDir = layout.projectDirectory.dir("oldsrc/").asFile
    commandLine = listOf("yarn", "run", "build")
}
s
I think you need to declare outputs as well. Run Gradle with —info to find out why a task is being rerun.
b
many thanks, got it
Copy code
tasks.register<Exec>("compileOldJs") {
    inputs.dir(layout.projectDirectory.dir("./oldsrc/src/"))
    outputs.dir(layout.projectDirectory.dir("./oldsrc/dist/"))
    workingDir = layout.projectDirectory.dir("oldsrc/").asFile
    commandLine = listOf("yarn", "run", "build")
}