Chmod permission '755' for executable at linux


(MERGHOOB) #1

Hi I write a task to change the permission for node-js executable, following is the code:

task changeNodeJSPermissionOnLinux(type: Exec) {
onlyIf {
project.ext.isLinux
}
commandLine ‘chmod’, ‘755’, “${nodejs_executable}”
}

I am getting following error:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘projectA:changeNodeJSPermissionOnLinux’.

Caused by: org.gradle.process.internal.ExecException: Process ‘command ‘chmod’’ finished with non-zero exit value 1


(Thorsten Schöning) #2

You seem to run chmod during the configuration phase, the path to node.js doesn’t exist yet at that time and the command fails. Try to use doLast instead, that gets executed at runtime of the task.

https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:defining_tasks

Configuration
During this phase the project objects are configured. The build scripts of all projects which are
part of the build are executed.

Execution
Gradle determines the subset of the tasks, created and configured during the configuration
phase, to be executed. The subset is determined by the task name arguments passed to the gradle
command and the current directory. Gradle then executes each of the selected tasks.