I need to run a Gradle task inside a shell environment, which must be created before the task is launched. Using commandLine or executable is not appropriate, as I need to run the task in the same process as the shell script. Originally, I called the script directly inside gradlew, but later I decided to source it from build.gradle.kts and call subsequent tasks through gradlew:
val setupRosEnv by tasks.creating(Exec::class) {
executable = "bash"
args("-c", "source $rosPath/setup.sh && source gradlew myTask")
}
I can build everything by running ./gradlew setupRosEnv from the CLI. Besides sourcing the script then running gradlew, is there a way to achieve this using the Gradle API? The current solution seems a bit hacky, and is clunky for other tasks to depend on setupRosEnv, as this will lead to an infinite loop or must be explicitly handled to prevent tasks being run more than once.
As the shell script itself is generated by ROS, it cannot be translated to Gradle or easily parsed.