I made custom task, name MySqlTask.groovy
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
public class MySqlTask extends DefaultTask {
def hostname = 'localhost'
def sql
@TaskAction
def runQuery() {
//to do something...
}
}
And, I put this file in rootProject/buildSrc/src/main/groovy.
My build file is customtasksourcetree.gradle.
task createDatabase(type: MySqlTask) { sql = 'CREATE DATABASE IF NOT EXISTS example' }
When I run gradle with customtasksrc.gradle then raise error like this.
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/need4spd/Programming/Java/workspace/gradleTest/customtasksourcetree.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'gradleTest'.
> Could not find property 'MySqlTask' on root project 'gradleTest'.
I have read that, my custom task file in buildSrc will compiled and add to classpath during build time automatically.
I can see compiled MySqlTask.class in buildSrc/build/classes.
What's the problem? Thanks.
I think that the problem is due to the fact that you haven't imported MySqlTask in your build script
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