yongseok Jang
yongseok Jang

Reputation: 97

gradle, could not find property in buildSrc

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.

Upvotes: 4

Views: 3901

Answers (1)

erdi
erdi

Reputation: 6954

I think that the problem is due to the fact that you haven't imported MySqlTask in your build script

Upvotes: 4

Related Questions