gradle cache转为local Maven库,解决gradle编译依赖包时常被墙

import glob,os,shutil
import distutils.dir_util,distutils.file_util

def mvtoparent(d):
    for dpath,dnames,fnames in os.walk(d):
        for fname in fnames:
            if  os.path.splitext(fname)[1] in ['.jar', '.pom']:
                print "move:", os.path.join(dpath,fname), os.path.join(os.path.dirname(dpath),fname)
                shutil.move(os.path.join(dpath,fname), os.path.join(os.path.dirname(dpath),fname))
                
def splitdir(d):
    mvtoparent(d)
    subd = d.split('.')
    resdir='\\'.join(subd)
    print "copytree:", d, resdir
    os.system("xcopy %s %s /S /Y"%(d,resdir))
    print "rm:", d
    shutil.rmtree(d)
    
basd = []
for dirpattern in ['org.*','com.*','net.*']:
    basd.extend(glob.glob(dirpattern))
print "convert dirs:", basd
for d in basd: splitdir(d)

转换完成后,记得修改build.gradle:

buildscript {
    repositories {
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.1'
        classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
    }
}


你可能感兴趣的:(gradle cache转为local Maven库,解决gradle编译依赖包时常被墙)