I have a Java class that I want to invoke from my gradle build script:
buildscript {
dependencies {
// This is the part I can't figure out...
classpath files("src/main/java/com/example")
}
}
import com.example.MyClass
task runner(dependsOn: 'classes') << {
def text = com.example.MyClass.doIt()
println text
}
The doIt()
method just returns a String.
Project layout looks like:
.
├── build.gradle
└── src
└── main
└── java
└── com
└── example
└── MyClass.java
I understand that I need to have the class added to the build script dependency, otherwise the import is not valid, but I don't understand how I can add the project source as a dependency for the build script. I've tried the following:
classpath project
classpath rootProject
classpath project(":gradle-test")
classpath files("src/main/java/com/example")
I can't get around
> startup failed:
build file '/Users/jameselsey/development/james-projects/gradle-test/build.gradle': 8: unable to resolve class com.example.MyClass
@ line 8, column 1.
import com.example.MyClass
^
1 error
How do I add MyClass
to the build script dependency?