Apply from broken by 3.4

(Enrico) #1

Before upgrading to gradle 3.4 I had a working configuration where my repository configuration was in a separate file and I could invoke it from my build script as follows

// repositories.gradle
RepositoryHandler.metaClass.myRepo = {
    delegate.maven {
        url ""
        credentials {
            username "user"
            password "hunter2"

// build.gradle
buildscript {
    apply from: "repositories.gradle"
    repositories {
allprojects {
    repositories {

After upgrading to gradle 3.4, ./gradlew build continued to work, but gradle sync in IntelliJ started to fail with the message

Gradle DSL method not found ‘myRepo()’

If it makes any difference, this is an Android project using version 2.3.0 of the Android gradle plugin.

I read the release notes, but nothing jumped out as the likely culprit.

How can I change my configuration to get gradle sync working again in 3.4+?

(Stefan Oehme) #2

If gradle build works, but Android Studio sync doesn’t, then I’d encourage you to open a bug on the Android bug tracker.

You could also try a workaround that doesn’t rely on Groovy metaClasses, but instead uses Gradle’s extension mechanism:

def myRepo = {...}
buildscript.repositories.ext.myRepo = myRepo
repositories.ext.myRepo = myRepo

The question is also if you actually need a function or whether you can just add the repository directly in repositories.gradle.

(Enrico) #3

OK. Thanks. I’ll try to put together a bug report for Android tools

Using the extension mechanism you suggested doesn’t seem to work at all. It breaks both gradle build and sync for 3.3 and 3.4. I get this error when I try to build

> Could not find method myRepo() for arguments [] on repository container.

For now I’ll stick with 3.3 and see what the Android tools team has to say