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...
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With