Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle plugin dependencies not found under buildSrc

Tags:

gradle

groovy

I have a working build.gradle that I'd like to refactor into the buildSrc directory but I'm having trouble finding the dependencies.

Working build.gradle:

import groovyx.net.http.HTTPBuilder

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

plugins {
  id 'groovy'
}

group "com.example"
version "0.0.1"

class Foo  {
  Foo() {
    new HTTPBuilder('http://www.example.com')
  }
}

Non-working refactored build.gradle:

However, when I try to split into the following:

build.gradle

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

plugins {
  id 'groovy'
}

group "com.example"
version "0.0.1"

and buildSrc/src/main/groovy/Foo.groovy

import groovyx.net.http.HTTPBuilder

class Foo  {
  Foo() {
    new HTTPBuilder('http://www.example.com')
  }
}

Gives the error:

C:\Project\buildSrc\src\main\groovy\Foo.groovy: 7: unable to resolve
class HTTPBuilder  @ line 5, column 26.
       HTTPBuilder client = new HTTPBuilder('http://www.example.com')

How can I get gradle to recognise the dependencies?

like image 938
chriskelly Avatar asked Jan 24 '18 16:01

chriskelly


1 Answers

You need to create a build.gradle file for buildSrc directory. Try this:

C:\Project\buildSrc\build.gradle

apply plugin: 'groovy'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.2'
}

There is more details in this documentation section.

like image 143
Edumelzer Avatar answered Sep 24 '22 13:09

Edumelzer