I have a multi project build in one of the sub-projects I would like to use some Groovy classes. After looking through the docs I created the buildSrc/src/main/groovy in the root project and placed a Groovy classes in there, see below
import org.yaml.snakeyaml.Yaml
class DatabaseHelper {
DatabaseHelper(){
Database targetTestDatabase
String databasesYaml = getLocalResource('databases.yaml')
Yaml beanLoader = new Yaml()
databases = beanLoader.loadAs(databasesYaml, HashMap.class)
}
}
Interestingly I do not declare any dependencies for org.yaml.snakeyaml.Yaml in the root project but build for buildSrc seems to work fine
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy
:buildSrc:processResources
:buildSrc:classes
:buildSrc:jar
:buildSrc:assemble
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test
:buildSrc:check
:buildSrc:build
In my sub project I have the below method which is called by a task
def getTargetDb(){
def databaseHelper = new DatabaseHelper()
Database targetTestDatabase = databaseHelper.targetTestDatabase
return targetTestDatabase
}
But when it runs I get the below
Caused by: java.lang.NoClassDefFoundError: org.yaml.snakeyaml.Yaml
at DatabaseHelper.class$(DatabaseHelper.groovy)
at DatabaseHelper.$get$$class$org$yaml$snakeyaml$Yaml(DatabaseHelper.groovy)
at DatabaseHelper.getLocalResource(DatabaseHelper.groovy:50)
at DatabaseHelper.<init>(DatabaseHelper.groovy:22)