I have a Java class that I want to call 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 simply returns a string.
The layout of the project is as follows:
. βββ build.gradle βββ src βββ main βββ java βββ com βββ example βββ MyClass.java
I understand that I need to add the class to the script assembly dependency, otherwise the import is not valid, but I do not understand how I can add the project source as a dependency for the script assembly, I tried the following:
classpath project classpath rootProject classpath project(":gradle-test") classpath files("src/main/java/com/example")
I can not 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 to add MyClass to build script dependency?
source share