1.先运行gradlew命令编译通过,此时会下载依赖到本地仓库

/gradlew clean assemble

2.运行gradlew命令检查所有依赖,防止缺少pom文件导致后续上传失败

./gradlew --refresh-dependencies

3.把以下gradle命令加到任意build.gradlew里,然后运行cacheToLocalMavenRepository任务,会把依赖生成在项目根目录下,并且目录结构满足maven上传时的格式

tasks.register("cacheToLocalMavenRepository", Copy) {
    duplicatesStrategy 'exclude'
    from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
    into rootDir.absolutePath + '/repolocal5.7_DKJT_VPN'
    eachFile {
        List<String> parts = it.path.split('/')
        print(parts.toString() + "\n")
        it.path = parts[0].replace('.', '/') + '/' + parts[1] + '/' + parts[2] + '/' + parts[4]
    }
    includeEmptyDirs false
}

4.使用以下shell脚本命令上传到maven仓库

./mvnupload.sh -u admin -p Passw0rd -r http://localhost:8081/repository/Android-Agent/

如脚本没有执行权限,执行命令chmod +x mvnupload.sh

5.mvnupload.sh脚本内容如下

#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
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}{} ;

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐