Commit af440985 authored by wengzhipeng@yit.com's avatar wengzhipeng@yit.com

Merge branch 'develop' into 'master'

Develop

See merge request !4
parents a5766785 a8cf96f4
apply plugin: 'maven'
def getConfigurationProperties() {
def configuration_file_name = "gradle.properties"
def path = "${projectDir.absolutePath + File.separator}$configuration_file_name"
println("configuration_file_name path is : $path")
def properties = new Properties()
new File(path).withInputStream {
stream -> properties.load(stream)
}
return new ConfigSlurper().parse(properties)
}
def getJenkinsProperties() {
if (System.getenv("JENKINS_HOME") == null) return null
def properties = new Properties()
new File("${System.getenv("JENKINS_HOME") + File.separator}.android_build.properties").withInputStream {
stream -> properties.load(stream)
}
def configSlurper = new ConfigSlurper().parse(properties)
if (configSlurper.RELEASE_URL == null) return null
if (configSlurper.SNAPSHOT_URL == null) return null
if (configSlurper.RELEASE_USERNAME == null) return null
if (configSlurper.SNAPSHOT_USERNAME == null) return null
if (configSlurper.RELEASE_PASSWORD == null) return null
if (configSlurper.SNAPSHOT_PASSWORD == null) return null
println("--------------------------------------------------------------")
println("---- SNAPSHOT_URL: $configSlurper.SNAPSHOT_URL")
println("---- SNAPSHOT_PASSWORD:$configSlurper.SNAPSHOT_PASSWORD")
println("---- SNAPSHOT_USERNAME:$configSlurper.SNAPSHOT_USERNAME")
println("---- RELEASE_URL: $configSlurper.RELEASE_URL")
println("---- RELEASE_PASSWORD: $configSlurper.RELEASE_PASSWORD")
println("---- RELEASE_USERNAME: $configSlurper.RELEASE_USERNAME")
println("--------------------------------------------")
return configSlurper
}
static def isReleaseBuild(def versionCode) {
if (versionCode == null) return false
return !versionCode.toUpperCase().contains("SNAPSHOT")
}
static def getMavenUrl(def configSlurper, def versionCode) {
if (configSlurper == null) return ""
if (configSlurper.RELEASE_URL == null) return ""
if (configSlurper.SNAPSHOT_URL == null) return ""
if (isReleaseBuild(versionCode)) {
return configSlurper.RELEASE_URL
}
return configSlurper.SNAPSHOT_URL
}
static def getUserName(def configSlurper, def versionCode) {
if (configSlurper == null) return ""
if (configSlurper.RELEASE_USERNAME == null) return ""
if (configSlurper.SNAPSHOT_USERNAME == null) return ""
if (isReleaseBuild(versionCode)) {
return configSlurper.RELEASE_USERNAME
}
return configSlurper.SNAPSHOT_USERNAME
}
static def getPassword(def configSlurper, def versionCode) {
if (configSlurper == null) return ""
if (configSlurper.RELEASE_PASSWORD == null) return ""
if (configSlurper.SNAPSHOT_PASSWORD == null) return ""
if (isReleaseBuild(versionCode)) {
return configSlurper.RELEASE_PASSWORD
}
return configSlurper.SNAPSHOT_PASSWORD
}
static def isNullOrEmpty(def val) {
return val == null || (val as String).replace(" ", "").length() == 0
}
uploadArchives {
def object
repositories {
mavenDeployer {
println('''
Script 使用步骤:
1、必须在模块的跟目录下创建文件名为 gradle.properties 的文件,模块跟目录,非项目跟目录
2、插件环境必须是Yit Jenkins 服务器
3、gradle.properties 文件下必须存在以下 key=value,key:配置名,Value: 配置值
GROUP=Value # 包的所属组
VERSION=Value # 包的版本,分为后缀为SNAPSHOT和无后缀,根据不同的后缀得到不同的上传环境
ARTIFACTID=Value # 包的mArtifactId
PACKAGING=Value # 打包模型,aar或jar,其他不支持
PROJECTNAME=Value # 项目名称,不做过多要求,仅不为空即可
4、模块必须有 com.android.library 或 java 插件
5、打包命令:gradle clean build uploadArchives -q :${module}:dependencies
6、:${module}:dependencies 为可选参数,尽量使用,可以输出当前包的依赖详情,module表示模块,若无可以直接使用 :dependencies
''')
if (!project.plugins.hasPlugin("com.android.library") && !project.plugins.hasPlugin("java")) {
throw new RuntimeException("project.plugins must is Android Library or Java Library")
}
object = pom
def mConfigurationConfigSlurper = getConfigurationProperties()
if (mConfigurationConfigSlurper == null) {
throw new RuntimeException("gradle.properties read failure")
}
def mGroup = mConfigurationConfigSlurper.GROUP == null ? "" : mConfigurationConfigSlurper.group
def mVersion = mConfigurationConfigSlurper.VERSION == null ? "" : mConfigurationConfigSlurper.VERSION
def mArtifactId = mConfigurationConfigSlurper.ARTIFACTID == null ? "" : mConfigurationConfigSlurper.ARTIFACTID
def mPackaging = mConfigurationConfigSlurper.PACKAGING == null ? "" : mConfigurationConfigSlurper.PACKAGING
def mProjectName = mConfigurationConfigSlurper.PROJECTNAME == null ? "" : mConfigurationConfigSlurper.PROJECTNAME
if (isNullOrEmpty(mGroup) || isNullOrEmpty(mVersion) || isNullOrEmpty(mArtifactId) || isNullOrEmpty(mPackaging) || isNullOrEmpty(mProjectName)) {
throw new RuntimeException("params[Group, Version, ArtifactId, Packaging ,ProjectName] must not null, values [$mGroup, $mVersion, $mArtifactId, $mPackaging, $mProjectName]")
}
if (mPackaging != "aar" && mPackaging != "jar") {
throw new RuntimeException("Packaging is aar or jar, Packaging is $mPackaging")
}
def mJenkinsConfigSlurper = getJenkinsProperties()
if (mJenkinsConfigSlurper == null) {
throw new RuntimeException("environment is not Jenkins")
}
def REPOSITORY_URL = getMavenUrl(mJenkinsConfigSlurper, mVersion)
def USERNAME = getUserName(mJenkinsConfigSlurper, mVersion)
def PASSWORD = getPassword(mJenkinsConfigSlurper, mVersion)
if (isNullOrEmpty(REPOSITORY_URL) || isNullOrEmpty(USERNAME) || isNullOrEmpty(PASSWORD)) {
throw new RuntimeException("jenkins environment failure,params [REPOSITORY_URL, USERNAME, PASSWORD] must not null, values [$REPOSITORY_URL, $USERNAME, $PASSWORD]")
}
println("GROUP:$mGroup\nVERSION:$mVersion\nARTIFACTID:$mArtifactId\nPackaging:$mPackaging\nProjectName:$mProjectName")
println("REPOSITORY_URL:$REPOSITORY_URL\nUSERNAME:$USERNAME\nPASSWORD:$PASSWORD")
repository(url: REPOSITORY_URL) {
authentication(userName: USERNAME, password: PASSWORD)
}
pom.project {
name mProjectName
version mVersion
artifactId mArtifactId
groupId mGroup
packaging mPackaging
description " "
}
}
}
project.getTasksByName("uploadArchives", true)
.each {
it.doLast {
println '--------------------------------------------------------------------------'
println "|"
println "| implementation '${object.groupId}:${object.artifactId}:${object.version}' "
println "|"
println '--------------------------------------------------------------------------'
}
}
}
ext {
app_version = "4.1.0"
shell = "4.1.0.5"
shell = "4.1.0.6"
shop = "4.1.0.1"
live = "4.1.0.3"
cms = "4.1.0.1"
cms = "4.1.0.2"
base = "4.1.0.4"
food = "4.1.0.1"
browser = "4.1.0.1"
......
apply from: "$rootDir.absolutePath/BuildScript/Register.Method.gradle"
//apply from: "$rootDir.absolutePath/BuildScript/Register.Method.gradle"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment