Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle, could not find property in buildSrc

Tags:

gradle

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.

like image 607
yongseok Jang Avatar asked Oct 23 '25 16:10

yongseok Jang


1 Answers

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

like image 126
erdi Avatar answered Oct 26 '25 09:10

erdi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!