Cannot import class in build.gradle file


(tulsoba) #1

I have made a custom gradle plugin project in eclipse. I build this project with gradle. In the root of my project I have my build.gradle file where I would like to include a class that I have made in the same project (src/com/MyClass.java):

apply plugin: 'groovy'
apply plugin: 'maven'
    repositories {
  mavenLocal()
  mavenCentral()
}
  dependencies {
  compile gradleApi()
  groovy localGroovy()
  compile 'commons-io:commons-io:2.4'
}
import com.MyClass;

But I get the error:

unable to resolve class import com.MyClass

How do import my own classes in the root build file? I have looked at this post:

http://forums.gradle.org/gradle/topics/cant_import_packages_to_gradle_build_file

which indicates that I need to inform the build script that it needs ‘this’ project but I am not sure how to.


(Peter Niederwieser) #2

See the “Organizing Build Logic” chapter in the Gradle User Guide. You can decide between 53.3 and 53.5. Another option is to declare a (Groovy) class right in the build script.