1. Meikel Brandmeyer
  2. local-dotgradle

Overview

HTTPS SSH

local-dotgradle

Motivation

One has to specify the repositories where gradle looks for dependencies in the build.gradle. However who says, that these repositories are always the same? For example in my work place there is some local repository proxy to be used. Now if I add it to the repositories, I can't compile the project somewhere else.

Therefor I wrote this little plugin: it checks whether some local.gradle file exists and loads it. This file might contain any customisations. Especially for my use case I added repository helpers: defaultRepositories and localRepositories.

Usage

Load the plugin:

    apply plugin: "local-dotgradle"

Then basically nothing happens. You can use your build.gradle as before. However if you create a file local.gradle, it will be loaded also. Ideally this file is not contained in the source code repository, but only added locally when there is a need for it.

To expand the example a little bit we will add some repositories.

    apply plugin: "local-dotgradle"

    defaultRepositories {
        mavenCentral()
    }

Without a local.gradle the build will just use maven central as desired. However if we create the following local.gradle the build automatically switches to the proxy definitions.

    localRepositories {
        mavenRepo urls: 'http://my.local.company/repository/proxy'
    }

Installation

Either download the plugin and place it in ${GRADLE_HOME}/lib/plugins or add the following to the top of your build.gradle.

    buildscript {
        repositories {
            mavenRepo urls: 'http://clojars.org/repo'
        }
        dependencies {
            classpath 'local-dotgradle:local-dotgradle:1.0.0'
        }
    }

Meikel Brandmeyer mb@kotka.de, Frankfurt am Main, 2011