1.打开云效->制品仓库->maven仓库->生产库/非生产库
2.点复制图标复制gradle方式推送代码?
3. 将代码粘贴在build.gradle
group 'com.ruoyi.generator'
description = 'ruoyi-generator'
version = '1.0.0'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
//下载云效依赖包仓库配置
repositories {
maven {
url = 'https://packages.aliyun.com/maven/repository/xxx-release-xxx/'
credentials {
username = 'xxx'
password = 'xxx'
}
}
maven {
url = 'https://packages.aliyun.com/maven/repository/xxx-snapshot-xxx/'
credentials {
username = 'xxx'
password = 'xxx'
}
}
}
dependencies {
implementation project(':ruoyi-common')
implementation project(':ruoyi-framework')
//velocity代码生成使用模板
api "org.apache.velocity:velocity-engine-core:${velocityVersion}"
//collections工具类
api "commons-collections:commons-collections:${collectionsVersion}"
}
bootJar {
enabled = false
}
jar {
enabled = true
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
sourceSets {
main {
resources {
srcDirs = ['src/main/resources']
}
}
}
//将当前工程打包上传到云效仓库
publishing {
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
from components.java
artifact sourcesJar
}
}
repositories {
maven {
allowInsecureProtocol true
name = "codeup"
//这里需要指定上传到生产库还是非生产库
url = 'https://packages.aliyun.com/maven/repository/xxx-release-xxx/'
credentials {
username = 'xxx'
password = 'xxx'
}
}
}
}
4.点publish推送包到云效仓库
?5.推送后可在云效仓库看到包
6.将仓库账号/密码设置到系统环境变量,避免多个人员开发密码提交冲突
# 需打开powershell执行以下代码,xxx替换为仓库对应地址/账号/密码
[environment]::SetEnvironmentvariable("MAVEN_REPO_SNAPSHOT_URL", "https://packages.aliyun.com/maven/repository/xxx-snapshot-xxx/", "User")
[environment]::SetEnvironmentvariable("MAVEN_REPO_RELEASE_URL", "https://packages.aliyun.com/maven/repository/xxx-release-xxx/", "User")
[environment]::SetEnvironmentvariable("MAVEN_DEPLOY_USER", "xxx", "User")
[environment]::SetEnvironmentvariable("MAVEN_DEPLOY_PASSWORD", "xxx", "User")
设置后查看环境变量如下
?
7.设置后build.gradle上的账号密码全部替换,代码如下
group 'com.ruoyi.generator'
description = 'ruoyi-generator'
version = '1.0.4'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
ext{
//获取环境变量
MAVEN_REPO_RELEASE_URL = System.getenv('MAVEN_REPO_RELEASE_URL')
MAVEN_REPO_SNAPSHOT_URL = System.getenv('MAVEN_REPO_SNAPSHOT_URL')
MAVEN_DEPLOY_USER = System.getenv('MAVEN_DEPLOY_USER')
MAVEN_DEPLOY_PASSWORD = System.getenv('MAVEN_DEPLOY_PASSWORD')
}
//从云效仓库下载依赖包
repositories {
maven {
credentials {
username MAVEN_DEPLOY_USER
password MAVEN_DEPLOY_PASSWORD
}
url MAVEN_REPO_RELEASE_URL
}
maven {
credentials {
username MAVEN_DEPLOY_USER
password MAVEN_DEPLOY_PASSWORD
}
url MAVEN_REPO_SNAPSHOT_URL
}
}
dependencies {
implementation project(':ruoyi-common')
implementation project(':ruoyi-framework')
//velocity代码生成使用模板
api "org.apache.velocity:velocity-engine-core:${velocityVersion}"
//collections工具类
api "commons-collections:commons-collections:${collectionsVersion}"
}
bootJar {
enabled = false
}
jar {
enabled = true
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
sourceSets {
main {
resources {
srcDirs = ['src/main/resources']
}
}
}
//将当前工程打包上传到云效maven仓库
publishing {
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
from components.java
artifact sourcesJar
}
}
repositories {
maven {
allowInsecureProtocol true
name = "codeup"
//这里需要指定上传到生产库还是非生产库
url = MAVEN_REPO_RELEASE_URL
credentials {
username MAVEN_DEPLOY_USER
password MAVEN_DEPLOY_PASSWORD
}
}
}
}