公共模块版本号统一管理
配置版本需要修改3个地方的文件,在此讲解app和library的工程版本配置。
工程目录如下图:
注意:下面我们说明中指定某个文件用这种方式:root/build.gradle(root目录下的build.gradle文件)
配置步骤
1 root/build.gradle文件修改
//apply from: 'https://raw.githubusercontent.com/szhittech/maven/master/config.gradle'
apply from: '../config.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
1.在root/build.gradle的开头增加一行代码即可:
apply from: '../config.gradle'
,公共模块的public根目录下有config.gradle
,这个文件一旦修改必须立马提交svn,这个很重要
2 root/gradle.properties文件修改
直接上代码吧,就是这么简单:
# gradle加速
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
#1.如果此处定义NEXUS_TYPE=maven,项目就提交到:https://oss.sonatype.org
#2.如果此处不定义或者定义NEXUS_TYPE的值不为mavan,那么项目提交到:http://200.200.200.40:8083/nexus
#NEXUS_TYPE=maven
# 如果要提交源码,就定义此变量,否则不定义;注意:仅仅只有快照版才能提交源码,如果是releasae版,定义了此变量也无效
SOURCESCODE
#GPG秘钥ID
signing.keyId=FB58CB54
#GPG秘钥密码
signing.password=2475431305
#GPG秘钥文件路径
signing.secretKeyRingFile=secring.gpg
1.如果此处定义NEXUS_TYPE=maven,项目就提交到:https://oss.sonatype.org
2.如果此处不定义或者定义NEXUS_TYPE的值不为mavan,那么项目提交到:http://200.200.200.40:8083/nexus
3
SOURCESCODE
是在发布SNATSHOT版的时候定义,表示将代码已源码形式发布,便于调试而已4 GPG秘钥信息,这些默认就可以了,用于发布JCenter的release版用
以上代码直接Copy到项目就可以
3 app/build.gradle文件修改
先上代码吧,^_^:
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
//andorid的编译版本配置
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
applicationId "com.het.bind"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
lintOptions{
abortOnError false
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//第三方库依赖
compile rootProject.ext.thirddependencies["appcompat-v7"]
//绑定模块
compile(rootProject.ext.dependencies["hetbinduisdk"]) { changing = true; }
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
1.Android的编译版本,照着写就OK了;
2.第三方库依赖示例:
compile rootProject.ext.thirddependencies["appcompat-v7"]
3.HeT模块依赖示例:以绑定模块的依赖为例(
compile(rootProject.ext.dependencies["hetbinduisdk"]) { changing = true; }
) 就这么简单,再也不用担心版本号了。
4 library/build.gradle文件修改
代码如下:
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
android {
//Android编译版本
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
lintOptions{
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(rootProject.ext.dependencies["hetbasicsdk"]) { changing = true; }
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
//设置modulename局部变量
ext {
//这个地方的设置一定要正确,很重要,填写错误后果很严重!
modulename = rootProject.ext.libsname.hetbindbizsdk
}
apply from: 'https://raw.githubusercontent.com/szhittech/maven/master/upload.gradle'
1.Android编译版本,照着写就OK;
2.设置modulename局部变量,这个设置很重要,书写规则:
modulename = rootProject.ext.libsname.xxx
这里的xxx就是项目名称,取值必须参照config.gradle
里面的libsname集合,后面展示config.gradle
源代码;3.发布的脚本依赖:
https://raw.githubusercontent.com/szhittech/maven/master/upload.gradle
,当然,如果网络不好,这个地方也可以配置成本地依赖4.删除library/gradle.properties
开始谈谈config.gradle配置文件吧,以后版本配置都是在这个文件里面配置,每次修改必须提交svn
Config.gradle配置文件
文件位置:http://61.141.158.190:1080/svn/repositories/android/code/trunk/public/config.gradle
建议将public整个文件夹从svn拉下来,然后可以用Android Studio去加载public目录中的项目,不要将项目单独拉下来
def isHet() {
def has = hasProperty('NEXUS_TYPE');
if (has) {
return NEXUS_TYPE.contains("maven") ? false : true;
} else {
return true;
}
}
//全局扩展参数
ext {
//默认参数配置
config = [GROUP : "com.github.szhittech",
POM_PACKAGING : "aar",
HET_NEXUS_RELEASES : "http://200.200.200.40:8083/nexus/content/repositories/releases/",//#发布releases版的地址
HET_NEXUS_SNAPSHOTS : "http://200.200.200.40:8083/nexus/content/repositories/snapshots/",//#发布snapshots版的地址
JCENTER_NEXUS_SNAPSHOTS: "https://oss.sonatype.org/content/repositories/snapshots/",//#JCenter快照版snapshots的地址
JCENTER_NEXUS_RELEASES : "https://oss.sonatype.org/service/local/staging/deploy/maven2/",//#JCenter快照版RELEASES 的地址
NEXUS_USERNAME : "szhittech",
NEXUS_PASSWORD : "het123456",
NEXUS_USERNAME_HET : "admin",
NEXUS_PASSWORD_HET : "admin123",
POM_DESCRIPTION : "szhittech",
POM_URL : "https://github.com/szhittech/szhittech",
POM_SCM_URL : "https://github.com/szhittech/szhittech",
POM_SCM_CONNECTION : "scm:git@github.com:szhittech/szhittech.git",
POM_SCM_DEV_CONNECTION : "scm:git@github.com:szhittech/szhittech.git",
POM_LICENCE_NAME : "The Apache Software License, Version 2.0",
POM_LICENCE_URL : "http://www.apache.org/licenses/LICENSE-2.0.txt",
POM_LICENCE_DIST : "repo",
POM_DEVELOPER_ID : "szhittech",
POM_DEVELOPER_ID : "szhittech"
]
allprojects {
repositories {
if (isHet()) {
//设置本地nexus仓库环境地址
maven { url config.HET_NEXUS_RELEASES }
maven { url config.HET_NEXUS_SNAPSHOTS }
} else {
//设置远程nexus仓库环境地址
maven { url config.JCENTER_NEXUS_SNAPSHOTS }
maven { url config.JCENTER_NEXUS_RELEASES }
}
}
}
//Android编译版本管理
android = [compileSdkVersion: 23,
buildToolsVersion: "23.0.1",
minSdkVersion : 15,
targetSdkVersion : 23,
versionCode : 1,
versionName : "1.0"]
//第三方依赖库
thirddependencies = ["appcompat-v7" : 'com.android.support:appcompat-v7:23.0.1',
"logging-interceptor": 'com.squareup.okhttp3:logging-interceptor:3.1.2',
"rxandroid" : 'io.reactivex:rxandroid:1.2.1',
"adapter-rxjava" : 'com.squareup.retrofit2:adapter-rxjava:2.0.2',
"retrofit" : 'com.squareup.retrofit2:retrofit:2.1.0',
"converter-gson" : 'com.squareup.retrofit2:converter-gson:2.0.0-beta3',
"gson" : 'com.google.code.gson:gson:2.6.2',
"activeandroid" : 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT',
"butterknife" : 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT',
"fresco" : 'com.facebook.fresco:fresco:0.9.0+'
]
//如果要提交release版,则定义snapshot=""
String snapshot = "-SNAPSHOT"
// String snapshot = ""
//HeT模块版本
libsversion = [hetapmodule : "1.0.0" + snapshot,//和而泰AP绑定(hetapmodule) 模组ID:28
hetsmartlink : "1.0.0" + snapshot, //和而泰smartlink绑定(在庆科基础上修改 hetsmartlink) 模组ID:10
realtekmodule : "1.0.0" + snapshot,//科中龙(realtekmodule) 模组ID:4
xlwmodule : "1.0.0" + snapshot,//新力维_NL6621底层库(xlwmodule) 模组ID:6
sctechmodule : "1.0.0" + snapshot,//双驰达(sctechmodule) 模组ID:15
elianmodule : "1.0.0" + snapshot,//信驰达_MTK7681底层库(elianmodule) 模组ID:5
marvellmodule : "1.0.0" + snapshot,//Marvell(marvellmodule) 模组ID:v1=8,v2=27
esptouchmodule : "1.0.0" + snapshot, //乐鑫信息科技(esptouchmodule) 模组ID:7
cooeemodule : "1.0.0" + snapshot,//博通(cooeemodule) 模组ID:20
hetlogsdk : "1.0.0" + snapshot,//全局日志库
hetbindbizsdk : "1.0.2" + snapshot,//绑定业务库
hetbinduisdk : "1.0.2" + snapshot,//绑定界面库
hetudpsdk : "1.0.4" + snapshot,//udp通讯库
hetxmlprotocolsdk: "1.0.0" + snapshot,//xml协议解析库
hetbasicsdk : "1.0.5" + snapshot//xml协议解析库
]
//HeT模块名称
libsname = [hetapmodule : "hetapmodule",
hetsmartlink : "hetsmartlink",
realtekmodule : "realtekmodule",
xlwmodule : "xlwmodule",
sctechmodule : "sctechmodule",
elianmodule : "elianmodule",
marvellmodule : "marvellmodule",
esptouchmodule : "esptouchmodule",
cooeemodule : "cooeemodule",
hetlogsdk : "hetlogsdk",
hetbindbizsdk : "hetbindbizsdk",
hetbinduisdk : "hetbinduisdk",
hetudpsdk : "hetudpsdk",
hetxmlprotocolsdk: "hetxmlprotocolsdk",
hetbasicsdk : "hetbasicsdk"
]
//HeT依赖库
dependencies = ["hetapmodule" : "${config.GROUP}:${libsname.hetapmodule}:${libsversion.hetapmodule}",
"hetsmartlink" : "${config.GROUP}:${libsname.hetsmartlink}:${libsversion.hetsmartlink}",
"realtekmodule" : "${config.GROUP}:${libsname.realtekmodule}:${libsversion.realtekmodule}",
"xlwmodule" : "${config.GROUP}:${libsname.xlwmodule}:${libsversion.xlwmodule}",
"sctechmodule" : "${config.GROUP}:${libsname.sctechmodule}:${libsversion.sctechmodule}",
"elianmodule" : "${config.GROUP}:${libsname.elianmodule}:${libsversion.elianmodule}",
"marvellmodule" : "${config.GROUP}:${libsname.marvellmodule}:${libsversion.marvellmodule}",
"esptouchmodule" : "${config.GROUP}:${libsname.esptouchmodule}:${libsversion.esptouchmodule}",
"cooeemodule" : "${config.GROUP}:${libsname.cooeemodule}:${libsversion.cooeemodule}",
"hetlogsdk" : "${config.GROUP}:${libsname.hetlogsdk}:${libsversion.hetlogsdk}",
"hetbindbizsdk" : "${config.GROUP}:${libsname.hetbindbizsdk}:${libsversion.hetbindbizsdk}",
"hetbinduisdk" : "${config.GROUP}:${libsname.hetbinduisdk}:${libsversion.hetbinduisdk}",
"hetudpsdk" : "${config.GROUP}:${libsname.hetudpsdk}:${libsversion.hetudpsdk}",
"hetxmlprotocolsdk": "${config.GROUP}:${libsname.hetxmlprotocolsdk}:${libsversion.hetxmlprotocolsdk}",
"hetbasicsdk" : "${config.GROUP}:${libsname.hetbasicsdk}:${libsversion.hetbasicsdk}"
]
}
//打印当前申明的library的版本号,编译操作者检查,根据此日志在提交的时候要核对版本正确性
ext.libsversion.each { //调用它的each函数,只要传入一个Closure就可以了。
println "###当前版本: ${it}"
}
//提交Maven的Task任务,此Task将提交工程中Setting.gradle中申明的所有library工程,执行此Task一定要检查library版本和依赖的正确性,要很慎重!!!
task upload() {
Set<Project> uploadProjects = new HashSet<>();
logger.lifecycle('【**下面是需要提交的项目列表,请仔细检查**】')
getSubprojects().each {
boolean isExists = it.getBuildFile().exists()
if (isExists) {
boolean isLibrary = it.getBuildFile().getText().contains('com.android.library')
if (isLibrary) {
boolean noSubProject = it.getSubprojects().isEmpty()
if (noSubProject) {
String pro = rootProject.ext.dependencies[it.name]
if (pro != null) {
logger.lifecycle('***正常:' + rootProject.ext.dependencies[it.name])
uploadProjects.add(it)
} else {
logger.log(LogLevel.ERROR, '***警告:' + it.name + '项目未配置版本控制,此项目提交未成功,请配置版本控制再提交!!!')
}
}
}
}
}
dependsOn {
uploadProjects.uploadArchives
}
}
ext.config变量、ext.android变量这些默认就可以了
第三方依赖库(thirddependencies )
把所有的第三方依赖的库,统统的放在这个地方管理,写法嘛,照着写!
HeT公共模块的版本添加管理
主要分三步,也就是分别在三个变量里面去添加(libsversion 、libsname 、dependencies )
参考
可以参考public/hetbindsdk,这个项目是已经改好的