在分布式系统开发中,基于gradle的项目,要共享jar一般是借助maven私服。那么gradle的maven插件如何做到上传binary jar,source jar, javadoc jar到私服呢?
选择http方式发布jar,则配置如下:
allprojects {
apply plugin: ‘java‘
apply plugin: ‘idea‘
apply plugin: ‘maven‘
idea {
module {
downloadSources=true
downloadJavadoc=true
}
}
configurations {
provided
compile.extendsFrom provided
deployerJars
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
snapshotRepository(url: “xxx repository snapshots") {
authentication(userName: “username", password: “password")
}
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = ‘sources‘
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = ‘javadoc‘
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
repositories {
maven {
name ‘xxx-repository‘
url ‘maven nexus repository‘
}
mavenLocal()
}
group ‘com.xxx‘
version ‘0.1.0-SNAPSHOT‘
sourceCompatibility = 1.7
}
subprojects {
dependencies {
deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
}
在做到上传之后,在下载的时候也需要能够自动关联到source jar,javadoc jar。
下载关联代码如下:
选择idea插件,则配置如下:
idea {
module {
downloadSources=true
downloadJavadoc=true
}
}
选择eclipse,则配置如下:
eclipse {
classpath {
downloadSources=true
downloadJavadoc=true
}
}