目录
一、Tomcat 部署 Nexus 仓库
发布到私服的话一般都是是使用Nexus(http://www.sonatype.org/nexus/go/)
一般公司内部会自己搭建私有Maven仓库,就把包发布到私有Maven仓库当中,以方便别人直接使用。
nexus-2.14.5-02.war 下载路径
链接:https://pan.baidu.com/s/1wuegWjV4wIB_mfyEn-8GIw
提取码:t372
把war包放入tomcat -webapps目录下,如下图, 重启 tomcat或服务器
浏览器输入网址 http://localhost:8080/nexus/
我们一般我们发布版会在Releases下面,快照版发布在sonatype下。
比如现在我需要发布在releases下面,点击releases站点:
二、配置 module build.gragle
module的build.gradle的脚本代码:
plugins {
id 'maven'
id 'maven-publish'
}
// 上传到私服
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
uploadArchives {
repositories {
mavenDeployer {
//正式环境
repository(url: properties.getProperty("POM_URL")) {
authentication(userName: properties.getProperty("nexus.user"), password: properties.getProperty("nexus.password"))
}
//snapshot环境
// snapshotRepository(url: properties.getProperty("POM_URL_snap")) {
// authentication(userName: properties.getProperty("nexus.user"), //password: properties.getProperty("nexus.password"))
// }
pom.groupId = properties.getProperty("POM_GROUP_ID")
pom.artifactId = properties.getProperty("POM_ATRIFACT_ID")
pom.version = properties.getProperty("POM_VERSION")
pom.project {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
uploadArchives 的配置了,我把对应的参数配置都藏在了local.poperties中,主要是6个参数的配置:
nexus.user=admin
nexus.password=admin123
//POM_URL_SNAP=http://119.23.109.196:8080/nexus/content/repositories/releases/
POM_URL=http://119.23.109.196:8080/nexus/content/repositories/releases/
POM_GROUP_ID=com.zeus.library
POM_ATRIFACT_ID=mylibrary
POM_VERSION=1.0.1
三、上传
为了上传需要加入 settings.gradle include ':mylibrary'
命令行或者任务都可以执行上传操作
D:\demo\Test>gradlew uploadArchives
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 2s
23 actionable tasks: 2 executed, 21 up-to-date
四、使用
去掉 settings.gradle include ':mylibrary'
首先在项目根目录下的build.gradle文件添加仓库url地址
build.gradle
allprojects {
repositories {
jcenter()
maven {
url "http://119.23.109.196:8080/nexus/content/repositories/releases/"
}
}
}
添加好我们的地址,然后在引用到该库的build.gradle中配置:
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'com.zeus.library:mylibrary:1.0.1'
}
然后运行项目就Ok了!