Thunderforge
Thunderforge

Reputation: 20585

How can I apply repositories from a remote script plugin to the pluginManagement block?

I would like to use the incubating plugins block to build.gradle:

plugins {
    id "com.jfrog.bintray" version "0.4.1"
}

By default, this pulls plugins from the Gradle plugin portal. However, we have a requirement in our organization that we need to use our internal Artifactory repository, rather than the public Gradle plugin portal or a similar repository.

I see that the pluginManagement block can be used to specify repositories, by adding the following to settings.gradle:

pluginManagement {
    repositories {
        maven {
            url "https://artifactory.example.com/"
        }
    }
}

We have several repositories, along with some credential logic, so in the past, we have just had this all bundled in a script plugin at a remote URL, then accessed it in our build.gradle file like so:

apply from: "https://shared.example.com/repositories.gradle"

The repositories.gradle file currently contains a repositories {} block that has several repositories.

Is there any way that I can apply this remote script plugin to the pluginManagement block? I tried going into my settings.gradle file and doing it this way:

pluginManagement {
    apply from: "https://shared.example.com/repositories.gradle"
}

However, I got the error message Could not find method repositories() for arguments. Is there some other way that I can get this to work?

Upvotes: 1

Views: 613

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14503

Just because you apply the external Gradle script in a specific context (e.g. pluginManagement), it won't be executed in this context. The apply method is implemented by the Settings object, so it is chosen as target object by default. You can try to delegate the script to another object by using the to parameter in the map you pass to the apply method:

apply to: pluginManagement, from: "https://shared.example.com/repositories.gradle"

Upvotes: 0

Related Questions