2

I am using a couple of helper classes with my build script, the folder structure looks like

buildSrc    
  -src   
     -main    
       -groovy
           GitUtils.groovy
build.gradle

In GitUtils I am trying to import a couple of classes (from grgit & http-builder in this example) used in a custom library. But it does not work, I get "Unable to resolve class XXX" exceptions. These classes are resolved fine if they are in build.gradle.

Relevant part of build.gradle:

buildscript {    
  repositories {
    jcenter()
    mavenCentral()
  }
  dependencies {
    classpath 'org.ajoberstar:grgit:1.3.0'
    classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
  }
}

dependencies {
  compile 'org.ajoberstar:grgit:1.3.0'
  compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
}

...
GitUtils.doStuff();
sydd
  • 1,824
  • 2
  • 30
  • 54

2 Answers2

2

The clean solution is to declare the dependencies you have in GUtils in your buildSrc/build.gradle file:

apply plugin:'groovy'

repositories {
  jcenter()
  mavenCentral()
}
dependencies {
  compile gradleApi()
  compile 'org.ajoberstar:grgit:1.3.0'
  compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
}
Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78
0

Since your buildSrc class is in groovy, please ensure the following are included in your build.gradle:

apply plugin: 'groovy'

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.2.1'
}
RaGe
  • 22,696
  • 11
  • 72
  • 104