我有多模块化项目。我导入了maven插件,可以在nexus上上传api和util jar。
这里是build.gradle的代码
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
allprojects {
apply plugin: 'idea';
apply plugin: 'java';
apply plugin: 'maven';
def propFile = file('gradle.properties')
def Properties props = new Properties()
props.load(new FileInputStream('gradle.properties'))
sourceCompatibility = props['SOURCE_COMPATIBILITY'];
targetCompatibility = props['TARGET_COMPATIBILITY'];
group = props['GROUP']
}
subprojects {
compileJava.options.encoding = 'utf-8'
propFile = file('gradle.properties')
Properties props = new Properties()
props.load(new FileInputStream(project.name + '/gradle.properties'))
ver = props['VERSION']
rel = props['RELEASE']
rev = props['REVISION']
archivesBaseName = props['ARCHIVES_BASE_NAME']
version = ver + '.' + rel + '.' + rev
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
propFile = file('gradle.properties')
props = new Properties()
props.load(new FileInputStream('gradle.properties'))
if (project.hasProperty('local')) {
repository(url: "$System.env.M2_LOCAL")
if (project.getProperties().get("v")) {
pom.version = project.getProperties().get("v")
} else {
if (project.hasProperty("iv")) {
switch (project.getProperties().get("iv").toString().toLowerCase()) {
case 'ver' :
props['VERSION'] = (ver.toInteger() + 1).toString();
props['RELEASE'] = "0";
props['REVISION'] = "0";
break
case 'rel' :
props['RELEASE'] = (rel.toInteger() + 1).toString();
props['REVISION'] = "0";
break
default :
props['REVISION'] = (rev.toInteger() + 1).toString();
}
} else {
props['REVISION'] = (rev.toInteger() + 1).toString()
}
pom.version = props['VERSION'] + '.' + props['RELEASE'] + '.' + props['REVISION']
pom.version = props['VERSION'] + '.' + props['RELEASE'] + '.' + props['REVISION']
props.store(propFile.newWriter(), null)
}
} else {
repository(url: "http://maven.wideup.net/nexus/content/repositories/releases/") {
authentication(userName: 'admin', password: project.getProperties().get("password"))
}
if (project.getProperties().get("v")) {
pom.version = project.getProperties().get("v")
} else {
if (project.hasProperty("iv")) {
switch (project.getProperties().get("iv").toString().toLowerCase()) {
case 'ver' :
props['VERSION'] = (ver.toInteger() + 1).toString();
props['RELEASE'] = "0";
props['REVISION'] = "0";
break
case 'rel' :
props['RELEASE'] = (rel.toInteger() + 1).toString();
props['REVISION'] = "0";
break
default :
props['REVISION'] = (rev.toInteger() + 1).toString();
}
} else {
props['REVISION'] = (rev.toInteger() + 1).toString()
}
pom.version = props['VERSION'] + '.' + props['RELEASE'] + '.' + props['REVISION']
props.store(propFile.newWriter(), null)
}
}
}
}
}
task localUpload << {
println maven
}
configurations {
provided
}
idea.module {
scopes.PROVIDED.plus += configurations.provided
}
repositories {
mavenLocal();
maven {
url 'http://maven.wideup.net/nexus/content/groups/public/'
}
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
afterEvaluate { prj ->
def isEar = prj.plugins.hasPlugin('ear')
if (isEar) {
configure(prj) {
dependencies {
}
if (ext.properties.containsKey('webModules')) {
deploymentDescriptor {
ext.properties.webModules.each {
webModule(dependencies.project(path: it.key).name + '-' + project.version + ".war", it.value)
}
}
}
}
task api(type: Jar, dependsOn: classes) {
archiveName = project(':comm.api').name + '-' + version + '.' + extension
from project(':comm.api').sourceSets.main.output
}
task sourcesApi(type: Jar, dependsOn: classes) {
archiveName = project(':comm.api').name + '-' + version + '-sources.' + extension
from project(':comm.api').sourceSets.main.allSource
}
} else {
configure(prj) {
dependencies {
}
}
}
}
}
现在我可以直接从终端命令拨打电话:
gradlew :comm.api:upload -Ppassword=somepassword
在这个方面使用evrytime并不是那么容易。 为了简化我创建的任务localUpload
我只需要打电话
gradlew :comm:api:localUpload
它在本地文件的某处找到存储库的密码,并调用方法上传将密码作为参数传递。
如何调用:comm.api:upload -Ppassword =从任务localUpload传递?