I'd like to run a given task, every time a file in the folder src
changes.
It seems that Gradle does not have a task like that, but there is the gradle-watch-plugin on github. Following the installation guide, I tried:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bluepapa32:gradle-watch-plugin:0.1.5'
}
}
apply plugin: 'com.bluepapa32.watch'
task "sometask" << {
println "My Own task."
}
watch {
somename {
files files('src')
tasks 'sometask'
}
}
Unfortunately this results in an error:
Starting:watch FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':watch'.
> org.gradle.tooling.BuildLauncher.withArguments([Ljava/lang/String;)Lorg/gradle/tooling/BuildLauncher;
So what's wrong with my build.gradle
?
You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class.
Running Gradle Commands To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … e.g. gradlew clean allTests.
Within IntelliJ IDEA, find the check task in the Gradle tool window under verification. Double click it to run.
This can be done without a plugin by enabling continuous mode in your build via the --continuous
or -t
command line argument. For example, given the following build script running gradle -t myTask
will automatically watch for changes in the folder src and reexecute the task when those files change.
task myTask {
inputs.files 'src'
doLast {
// do some stuff with files in 'src' folder
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With