1、 需打开powershell执行以下代码,value替换为仓库对应地址/账号/密码
[environment]::SetEnvironmentvariable("MAVEN_REPO_SNAPSHOT_URL", "https://packages.aliyun.com/maven/repository/2xxx-snapshot-1wNmas/", "User")
[environment]::SetEnvironmentvariable("MAVEN_REPO_RELEASE_URL", "https://packages.aliyun.com/maven/repository/xxx-release-Y8y0H2/", "User")
[environment]::SetEnvironmentvariable("MAVEN_DEPLOY_USER", "5ed75aaxxxx5a83af", "User")
[environment]::SetEnvironmentvariable("MAVEN_DEPLOY_PASSWORD", "e2gxxxxsi", "User")
2、gradle配置示例
plugins {
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.fafa'
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
sourceCompatibility = 17
targetCompatibility = 17
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 { url "https://maven.aliyun.com/nexus/content/groups/public/" }
maven {
url 'https://maven.aliyun.com/repository/public'
}
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org/m2/" }
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
}
mavenCentral()
}
dependencies {
//Spring Boot Web 启动器
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
sourceSets {
main {
resources {
srcDirs = ['src/main/resources']
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
doLast {
copy {
from sourceSets.main.resources
into "$buildDir/resources/main"
}
}
}
}