要想deploy打包好的项目到公司服务器到nexus上,那服务器上nexus需要把deploy权限给打开咯。
这个是release的服务器repository,注意下后面的地址以及下面的权限开关,allow redeploy。允许deploy。
然后就是gradle在项目里面的build.gradle文件里面配置了。
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"
}
}
}
1,引入maven插件:apply plugin: 'maven' // 引入maven插件
2,设置下group和version,repositories(这个应该是先local,再URL,再central,上面的是先URL了。)
上面的配置参考一下,应该够用了。配置完之后,就可以在侧边栏看到如下的2个maven的命令了。
install一下,就可以打包发布到本地的repository了,一般是在.m2/repository/.......
uploadArchives,执行就发布到nexus服务器上了。
看下发布的结果截图和其他一些说明
1,发布snapshot版本到nexus服务器上的截图
可以看到,发布一次snapshot,上面就多一个,这12345个
2,deploy release版本到nexus服务器上的截图
这个release发布了几次,nexus服务器上就始终是一个。
3,在使用2个发布的时候,还是有点不一样的。
记得修改version后面的-release或者-snapshot。
发布上去之后,就能像使用其他公共的jar依赖一样使用自己刚刚发布的jar依赖了。
4,可以看到发布到local nexus服务器上到jar的一些信息
使用依赖,maven格式的,gradle要用的话,自己改一下就好了。
可以看到,你刚刚发布到服务器的jar依赖的最后更新时间,这个时间是服务器时间,可能和你本地的时间有点差距,注意一下。
根据这个时间变化与否,判断是否发布成功。
5,你这发布上去,可能一会儿就几次,使用这个依赖的小伙伴可能本地有缓存,无法下载使用到你最新发布的jar。
怎么办?看下面的链接。