Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify different repositories when using Cordova gradle wrapper

I'm using Cordova Android 4.0.0 which uses a gradle wrapper to build. I need to specify a different repository than mavenCentral. I can't simply modify the build.gradle file because it's auto-generated by Cordova. Because it's using the wrapper distribution specified by Cordova I can't add an /init.d to the distribution. I've tried adding a USER_HOME/.gradle/init.gradle file which doesn't seem to be getting used. Is there some other way to specify an init file when using a wrapper that I don't have control over?

EDIT: As a workaround for now I've added an after_prepare hook that changes the text "mavenCentral()" found anywhere in the build.gradle files to the repo I need to use instead. There's got to be a better gradle based solution though...

like image 585
SunshinyDoyle Avatar asked Mar 17 '23 04:03

SunshinyDoyle


1 Answers

We use ionic and have our own nexus repository that we use instead of mavenCentral. We ended up creating a hook to resolve this open issue

by adding a hook :

module.exports = function(ctx) {
    'use strict';
    var fs = ctx.requireCordovaModule('fs'),
        path = ctx.requireCordovaModule('path'),
        deferral = ctx.requireCordovaModule('q').defer(),
        replaceStream = require('replacestream'),
        async = require('async');
    var platformRoot = path.join(ctx.opts.projectRoot, 'platforms/android');
    var gradleFiles = [path.join(platformRoot, 'build.gradle'), path.join(platformRoot, 'CordovaLib', 'build.gradle')];
    async.each(gradleFiles, function(f, cb) {
        fs.readFile(f, 'utf8', function(err, data) {
            if (err) {
                cb(err);
                return;
            }
            var result = data.replace(/mavenCentral\(\)/g, 'maven{url "http://nexus.corp.aal.au/content/groups/public-ad"}');
            fs.writeFile(f, result, 'utf8', cb);
        });
    }, function(err) {
        if (err) {
            deferral.reject();
        } else {
            deferral.resolve();
        }

    });
    return deferral.promise;
}
like image 134
Arun Gopalpuri Avatar answered Mar 21 '23 14:03

Arun Gopalpuri