Gradle上傳依賴到私服(nexus)
阿新 • • 發佈:2020-12-05
子模組配置
buildscript { repositories { mavenLocal() maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } maven { url "${nexusUrl}" credentials { username "${username}" password "${password}" } } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } repositories { mavenLocal() maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } maven { url "${nexusUrl}" credentials { username "${username}" password "${password}" } } } apply plugin: 'maven' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' bootJar.enabled = false jar.enabled = true dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } task sourceJar(type: Jar) { from sourceSets.main.allJava } uploadArchives { repositories { mavenDeployer { pom.groupId = "com.hcg" pom.version = "1.0" pom.artifactId = "common-util" repository(url: "${nexusUrl}") { authentication(userName: "${username}", password: "${password}") } } } } dependencies { compile group: 'com.alibaba', name: 'fastjson', version: '1.2.58' }
父模組build.gradle
project.ext { springBootVersion = '2.0.3.RELEASE' springCloudVersion = 'Finchley.RELEASE' nexusUrl = 'http://39.98.129.242:8081/repository/hcg-releases/' username = 'admin' password = '密碼' } allprojects { group 'com.hcg' } subprojects { apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = 11 targetCompatibility = 11 repositories { mavenLocal() } dependencies { } }
說明
如果只是子模組只要將變數替換即可
${nexusUrl}:倉庫地址
${username}:使用者
${password}:密碼
上傳命令
gradle uploadArchives