天天看點

gradle 釋出jar包到nexus

在build.gradle中這樣配置

group 

'july'

version '

1.5.0-SNAPSHOT

'

def

artifactId = 

"young"

apply plugin: 

'java'

apply plugin: 

'maven'

apply plugin: 'maven-publish'//添加Maven釋出插件

...

//打包源代碼

task sourcesJar(type: Jar, dependsOn: classes) {

classifier = 

'sources'

from sourceSets.main.allSource

}

artifacts {

archives sourcesJar

}

...

//如果希望gradle install,安裝到.m2本地倉庫,參考下面的内容

install {

repositories.mavenInstaller {

pom.version = 

"$project.version"

pom.artifactId = 

"$artifactId"

pom.groupId = 

"$project.group"

}

}

//上傳到nexus

uploadArchives {

repositories {

mavenDeployer {

repository(url: 

"http://localhost:8081/nexus/content/repositories/thirdparty"

) {

authentication(userName: 

"admin"

, password: 

"admin123"

)

}

pom.version = 

"$project.version"

pom.artifactId = 

"$artifactId"

pom.groupId = 

"$project.group"

}

}

}

配置完成後在項目的根目錄下打開cmd.exe,輸入下面的指令:gradle upload 

如果出現400錯誤,請确定你的版本是否為 snapshot ,如果不是請改成snapshot