将 gradle 缓存转换为本地 maven 仓库及上传到 nexus gradle 将 maven 仓库中的所有依赖库下载到本地缓存文件夹中。但是此缓存文件夹不可移植。如果我们将此缓存文件夹从我们的 PC 传输到另一台 PC,gradle 将无法识别 gradle 缓存的复制版本。同时我们无法简单的做到将缓存的 gradle 上传到 nexus 中
事情的起因是我依赖的 https://artifacts.alfresco.com/nexus/content/repositories/
突然需要进行 HTTP Basic
认证,导致我的打包脚本无法正常执行,所以我要将本地缓存的相关包转移到 nexus 中去
将 gradle cache 转换为 maven local 通过搜索 github,找到了 gradle-cash-to-maven-repo
通过此代码(python3)可以很方便将 gradle cache 转换为 maven local
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 import osfrom shutil import copyfilelogging = False src = "E:/android/gradle_home/caches/modules-2/files-2.1/" dst = "E:/android/gradle_local_repo/" group_count = 0 artifect_count = 0 def getTransformedPath (path ): transformedPath = path.replace("/" , "\\" ) transformedPath = "\\\\?\\" + transformedPath return transformedPath def makedirs (path ): if not os.path.exists(path): os.makedirs(path) return def processGroup (group ): global group_count group_count = group_count + 1 group_dir = group.replace("." , "/" ) if (logging): print (group_dir) makedirs(dst + group_dir) artifects = os.listdir(src + group) for artifect in artifects: processArtifect(group, group_dir, artifect) return def processArtifect (group, group_dir, artifect ): global artifect_count artifect_count = artifect_count + 1 artifect_dir = dst + group_dir + "/" + artifect makedirs(artifect_dir) if (logging): print (artifect) src_artifect_dir = src + group + "/" + artifect versions = os.listdir(src_artifect_dir) for version in versions: processVersion(group, artifect, artifect_dir, version) return def processVersion (group, artifect, artifect_dir, version ): version_dir = artifect_dir + "/" + version makedirs(version_dir) if (logging): print (version) src_version_dir = src + group + "/" + artifect + "/" + version hashs = os.listdir(src_version_dir) for hash in hashs: hash_dir = src_version_dir + "/" + hash files = os.listdir(hash_dir) for file in files: src_file_path = hash_dir + "/" + file dst_file_path = version_dir + "/" + file src_file_path = getTransformedPath(src_file_path) dst_file_path = getTransformedPath(dst_file_path) copyfile(src_file_path, dst_file_path) return groups = os.listdir(src) for group in groups: processGroup(group) print ("Done!" )print ("Total %d groups" %(group_count))print ("Total %d artifects" %(artifect_count))
maven 本地仓库同步上传到 nexus 远程仓库 maven 本地仓库同步上传到 nexus 远程仓库
备份
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/bin/bash while getopts ":r:u:p:" opt; do case $opt in r) REPO_URL="$OPTARG " ;; u) USERNAME="$OPTARG " ;; p) PASSWORD="$OPTARG " ;; esac done find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME :$PASSWORD " -X PUT -v -T {} ${REPO_URL} {} ;
1 2 3 4 5 cd 转换后路径./mavenimport.sh -u admin -p admin123 -r http://nexus.lizz.com/repository/lizz_test