gradle deploy 打包后自动上传到nexus仓库

    技术2022-07-11  90

    转载:https://lixuekai.blog.csdn.net/article/details/98747023

    要想deploy打包好的项目到公司服务器到nexus上,那服务器上nexus需要把deploy权限给打开咯。

    这个是release的服务器repository,注意下后面的地址以及下面的权限开关,allow redeploy。允许deploy。

    然后就是gradle在项目里面的build.gradle文件里面配置了。

    引入maven 插件

     

    group 'com.xxx.xxx' version '1.0-release' def artifactId = "collector-sql" apply plugin: 'java' apply plugin: 'maven' // 引入maven插件 sourceCompatibility = 1.8 repositories { maven { url "http://192.168.1.155:8081/nexus/content/groups/xxxxGroup/" } mavenLocal() mavenCentral() } dependencies { compile project(':collector:collector-processor') testCompile 'junit:junit:4.12' } //打包源代码 task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } artifacts { archives sourcesJar } //如果希望gradle install,安装到.m2本地仓库,参考下面的内容 install { repositories.mavenInstaller { pom.groupId = "$project.group" pom.artifactId = "$artifactId" pom.version = "$project.version" } } //上传到nexus-snapshot,记得改名字,version的值以snapshot结尾 //uploadArchives { // repositories { // mavenDeployer { // repository(url: "http://192.168.1.155:8081/nexus/content/repositories/xxxsnapshot-s/") { // authentication(userName: "userName", password: "password") // } // pom.groupId = "$project.group" // pom.artifactId = "$artifactId" // pom.version = "$project.version" // } // } //} //上传到 nexus-release,记得改名字,version的值以release结尾 uploadArchives { repositories { mavenDeployer { repository(url: "http://192.168.1.155:8081/nexus/content/repositories/releases/") { authentication(userName: "userName", password: "password") } pom.groupId = "$project.group" pom.artifactId = "$artifactId" pom.version = "$project.version" } } }

    gradle 强制清除 缓存的依赖,再次主动下载

    Windows:     gradlew build --refresh-dependencies  Mac: ./gradlew build --refresh-dependencies  

     

    Processed: 0.010, SQL: 9