Commit 70a2eec7 by 王涛55

feat:修改

parent d03cad90
apply plugin: 'android-aspectjx'
aspectjx {
// //织入遍历符合条件的库
// includeJarFilter 'universal-image-loader', 'AspectJX-Demo/library'
//排除包含‘universal-image-loader’的库
// excludeJarFilter 'universal-image-loader'
// excludeJarFilter 'org.apache.httpcomponents'
// excludeJarFilter '.jar'
}
/*
* Copyright (C) 2017 贵阳货车帮科技有限公司
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: file("${rootDir}/BuildScript/global_config.gradle")
apply from: file("${rootDir}/BuildScript/global_function.gradle")
buildscript { buildscript {
repositories { repositories {
google()
jcenter() jcenter()
maven { maven { url 'https://dl.bintray.com/umsdk/release' }
// Android Team 开发的公共库稳定发布版本
name 'wlqq-releases'
url 'http://nexus.56qq.cn:81/content/repositories/wlqq-releases'
}
maven {
// Android Team 开发的公共库开发快照版本
name 'wlqq-snapshots'
url 'http://nexus.56qq.cn:81/content/repositories/wlqq-snapshots'
}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.tencent.bugly:symtabfileuploader:1.3.9' classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1' classpath "com.alibaba:arouter-register:1.0.2"//For ARouter
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath "com.tencent.bugly:tinker-support:1.1.5"//tinker
classpath 'org.aspectj:aspectjtools:1.8.9'
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:1.0.10'
classpath 'de.undercouch:gradle-download-task:3.2.0'
classpath 'com.vanniktech:gradle-android-apk-size-plugin:0.3.0'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.10.0'
classpath 'com.wlqq.android:gradle-plugin-exclude:1.3.0'
classpath 'com.wlqq.android:gradle-plugin-replace:1.0.0-SNAPSHOT'
classpath 'com.wlqq.android:gradle-plugin-debugger:1.0.0'
} }
} }
allprojects { allprojects {
repositories { repositories {
maven { google()
// JCenter 代理仓库
url 'http://nexus.56qq.cn:81/content/repositories/bintray'
}
jcenter() jcenter()
maven { url "https://www.jitpack.io" } maven {//For ali云推送
maven { url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
// 第三方没有提供 maven 仓库的 SDK jar 包
url 'http://nexus.56qq.cn:81/content/repositories/thirdparty'
} }
maven { maven {//For JsBridge
// Android Team 开发的公共库稳定发布版本 url "https://jitpack.io"
name 'wlqq-releases'
url 'http://nexus.56qq.cn:81/content/repositories/wlqq-releases'
} }
maven { maven {//For 友盟统计
// Android Team 开发的公共库开发快照版本 url 'https://dl.bintray.com/umsdk/release'
name 'wlqq-snapshots'
url 'http://nexus.56qq.cn:81/content/repositories/wlqq-snapshots'
} }
} }
} }
subprojects { subProject -> task clean(type: Delete) {
// fix : 编码GBK的不可映射字符 delete rootProject.buildDir
// gradle 版本 2.0 以下的用户请将 JavaCompile 改为 Compile
subProject.tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
plugins.withId('com.android.application') {
subProject.apply from: file("${project.rootDir}/BuildScript/code_analysis/findbugs.gradle")
}
plugins.withId('com.android.library') {
subProject.apply from: file("${project.rootDir}/BuildScript/code_analysis/findbugs.gradle")
}
plugins.withId('java') {
subProject.apply from: file("${project.rootDir}/BuildScript/code_analysis/findbugs-java.gradle")
}
apply from: file("${project.rootDir}/BuildScript/code_analysis/pmd.gradle")
apply from: file("${project.rootDir}/BuildScript/code_analysis/checkstyle.gradle")
afterEvaluate { project ->
if (project.hasProperty("android")) {
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion COMPILE_SDK_VERSION
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION
}
signingConfigs {
release {
// 如果要支持最新版的系统 Android 7.0
// 这一行必须加,否则安装时会提示没有签名
// 作用是只使用旧版签名,禁用 V2 版签名模式
// 详见:https://github.com/mcxiaoke/packer-ng-plugin/blob/master/compatibility.md
v2SigningEnabled false
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
xmlReport true
htmlReport false
lintConfig file("${project.rootDir}/BuildScript/code_analysis/lint.xml")
}
packagingOptions {
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
}
}
} }
// Define versions in a single place
class VersionConfig {
String versionName
int versionCode
@Override
public String toString() {
return """\
VersionConfig{
versionName='$versionName',
versionCode=$versionCode
}"""
}
}
/**
* 基于语意化版本配置生成版本信息
*
* @see <a href="https://www.tapd.cn/20032611/markdown_wikis/view/#1120032611001009351">Android 端产品版本命名方案</a>
*
* @param major 产品大改版,比如:司机版从 4.x 到 5.x。取值范围 1..99
* @param middle 增加了大的功能模块(二手车、停车场)。取值范围 0..99
* @param minor 原功能模块的小改进。取值范围 0..99
* @param branch 用于验证技术方案的支线版本(例如司机版 TAB 动态化运营),取值范围 0..9。若大于零,说明是支线版本
* @param patch 紧急封包(hotfix 或打包新版本的插件),取值范围 0..9 。若大于零,说明是紧急封包版本
* @return
*/
VersionConfig generateVersionConfig(int major, int middle, int minor, int branch, int patch) {
if (major < 1 || major > 99) {
throw new GradleException("major expected in 1..99, but actual: ${major}")
}
if (middle < 0 || middle > 99) {
throw new GradleException("middle expected in 0..99, but actual: ${middle}")
}
if (minor < 0 || minor > 99) {
throw new GradleException("minor expected in 0..99, but actual: ${minor}")
}
if (branch < 0 || branch > 9) {
throw new GradleException("branch expected in 0..9, but actual: ${branch}")
}
if (patch < 0 || patch > 9) {
throw new GradleException("patch expected in 0..9, but actual: ${patch}")
}
String versionName
int versionCode
if (patch > 0) {
versionName = "$major.$middle.$minor.$branch.$patch"
} else if (branch > 0) {
versionName = "$major.$middle.$minor.$branch"
} else {
versionName = "$major.$middle.$minor"
}
versionCode = major * 1000000 + middle * 10000 + minor * 100 + branch * 10 + patch
return new VersionConfig('versionName': versionName, 'versionCode': versionCode)
}
def android_support_version = '25.3.1'
def android_test_support_version = '0.5'
def espresso_version = '2.2.2'
ext { ext {
// app version
gradleDependencies = [ versionCode = 171
"support-v4" : "com.android.support:support-v4:${android_support_version}", versionName = "1.7.1"
"cardview-v7" : "com.android.support:cardview-v7:${android_support_version}",
"appcompat-v7" : "com.android.support:appcompat-v7:${android_support_version}", // Sdk and tools
"recyclerview-v7" : "com.android.support:recyclerview-v7:${android_support_version}", // tool version
"support-annotations" : "com.android.support:support-annotations:${android_support_version}", minSdkVersion = 19
"awesomelog" : "io.github.shaobin0604:awesomelog:1.0.1", targetSdkVersion = 28
"BaseRecyclerViewAdapterHelper": "com.github.CymChad:BaseRecyclerViewAdapterHelper:v1.9.7", compileSdkVersion = 28
"base-adapter-helper" : "com.joanzapata.android:base-adapter-helper:1.1.11",
"protobuf-java" : "com.google.protobuf:protobuf-java:2.4.1", // Support library
"atsl-runner" : "com.android.support.test:runner:${android_test_support_version}", supportLibraryVersion = '28.0.0'
"atsl-rules" : "com.android.support.test:rules:${android_test_support_version}", multidexVersion = "1.0.3"
"espresso-core" : "com.android.support.test.espresso:espresso-core:${espresso_version}", guavaVersion = '22.0-android'
"espresso-contrib" : "com.android.support.test.espresso:espresso-contrib:${espresso_version}", constraintLayout = "1.1.3"
"uiautomator-v18" : "com.android.support.test.uiautomator:uiautomator-v18:2.1.2",
] // butterknife
butterknife = '8.8.1'
// SmartRefreshLayout
smartRefreshLayout = '1.1.0-alpha-19'
// alicloud push
alicloudPush = '3.1.4'
// BackgroundLibrary
backgroundLibrary = '1.5.1'
// qrcode
zxing = "3.3.3"
// NumberPickerView
numberPickerView = '1.1.1'
// ARouter
aRouterApi = '1.4.1'
aRouterCompiler = '1.2.2'
// rx
retrofit2Version = '2.3.0'
rxandroidVersion = '2.0.1'
loggingInterceptor = '3.12.+'
// json tool -- to do
fastJsonVersion = '1.2.6'
googleGsonVersion = '2.7'
// permission need to use compileSdkVersion 27 or higher. -- to do
easyPermissions = '1.2.0'
// Architecture Components dependencies
roomVersion = "1.1.1"
archLifecycleVersion = "1.1.1"
// image
gliderVersion = "4.9.0"
// jsbridge
jsbridge = '1.0.4'
//LabelsView
labelsView='1.4.7'
//svg
androidsvg = '1.3'
//rating bar
materialratingbar = '1.3.2'
//bannerView
bannerView = '1.4.10'
// test -- to do
junitVersion = '4.12'
mockitoVersion = '1.10.19'
powerMockito = '1.6.2'
hamcrestVersion = '1.3'
runnerVersion = '1.0.2'
rulesVersion = '1.0.1'
espressoVersion = '3.0.2'
// u meng
umengAnalytics = '8.0.0'
umengCommon = '2.0.0'
//bugly tinker
multidex = '1.0.2'
tinkerVersion = '1.9.9'
bugly_crashreport ='1.3.8'
bugly_native_crashreport ='latest.release'
meituanWalle = '1.1.3'
} }
apply plugin: 'de.undercouch.download'
import java.util.regex.Pattern
class Globals {
static final String DOWNLOAD_URL_PREFIX = 'http://10.2.1.117:9999'
static final String RELEASE_BUILD_DOWNLOAD_URL_PREFIX = DOWNLOAD_URL_PREFIX + '/release_build'
static final String DAILY_BUILD_DOWNLOAD_URL_PREFIX = DOWNLOAD_URL_PREFIX + '/test_build'
static final String BUILTIN_PLUGIN_LIST_CSV_FILE = 'builtin_plugin_list.csv'
}
/**
* 删除参数指定目录下的匹配文件名前缀的文件
*
* @param dir 目录名
* @param apkFileNamePrefix APK 文件前缀名
* @return
*/
static def deletePluginApkFile(String dir, String apkFileNamePrefix) {
new File(dir).eachFile() { file ->
if (file.name.startsWith(apkFileNamePrefix)) {
file.delete()
}
}
}
/**
* 获取插件指定版本<b>稳定版</b>下载链接
*
* @param remoteDir 远程服务器上插件 APK 所在目录名
* @param packageName 插件包名
* @param versionName 插件版本名
* @return 下载链接
*/
static def getStableVersionUrl(String remoteDir, String packageName, String versionName) {
return "${Globals.RELEASE_BUILD_DOWNLOAD_URL_PREFIX}/${remoteDir}/${packageName}_${versionName}.apk"
}
/**
* 获取插件指定版本<b>快照版</b>下载链接
*
* @param remoteDir 远程服务器上插件 APK 所在目录名
* @param packageName 插件包名
* @param versionName 插件版本名
* @return 下载链接
*/
static def getSnapshotVersionUrl(String remoteDir, String packageName, String versionName) {
return "${Globals.DAILY_BUILD_DOWNLOAD_URL_PREFIX}/${remoteDir}/${packageName}_${versionName}.apk"
}
/**
* 获取插件最新的<b>快照版</b>下载链接
*
* @param remoteDir
* @return 下载链接
*/
static def getLatestSnapshotVersionUrl(String remoteDir) {
def filename = "${Globals.DAILY_BUILD_DOWNLOAD_URL_PREFIX}/${remoteDir}/filename.txt".toURL().text
return "${Globals.DAILY_BUILD_DOWNLOAD_URL_PREFIX}/${remoteDir}/${filename}"
}
/**
* 下载插件指定版本<b>稳定版</b>到指定的本地目录
*
* @param remoteDir 远程服务器上插件 APK 所在目录名
* @param packageName 插件包名
* @param versionName 插件版本名
* @param localDir 本地存储目录
* @return
*/
def downloadPluginStableVersion(String remoteDir, String packageName, String versionName, String localDir) {
def pluginDir = localDir
deletePluginApkFile(pluginDir, packageName)
download {
src getStableVersionUrl(remoteDir, packageName, versionName)
dest pluginDir
}
}
/**
* 下载插件指定版本<b>快照版</b>到指定的本地目录
*
* @param remoteDir 远程服务器上插件 APK 所在目录名
* @param packageName 插件包名
* @param versionName 插件版本名
* @param localDir 本地存储目录
* @return
*/
def downloadPluginSnapshotVersion(String remoteDir, String packageName, String versionName, String localDir) {
println "[downloadPluginSnapshotVersion] ${packageName}:${versionName}"
def pluginDir = localDir
deletePluginApkFile(pluginDir, packageName)
def url = null
if ('+' == versionName) {
url = getLatestSnapshotVersionUrl(remoteDir)
} else {
url = getSnapshotVersionUrl(remoteDir, packageName, versionName)
}
download {
src url
dest pluginDir
}
}
/**
* 生成内置插件列表描述文件 <code>assets/builtin_plugin_list.csv</code>
*
* 在 assets 目录下匹配符合插件命名规范的 APK 文件 <code>${package_name}_${version_name}.apk</code> ,生成对应
* 的内置插件描述信息
* <ul>
* <li>filename</li>
* <li>packageName</li>
* <li>versionName</li>
* <li>versionCode</li>
* </ul>
* 写入 csv 文件 <code>assets/builtin_plugin_list.csv</code>
* <pre>
* csv file, line format: ${filename},${packageName},${versionName},${versionCode}
* e.g. com.wlqq.phantom.plugin.wallet_2.1.9.apk,com.wlqq.phantom.plugin.wallet,2.1.9,20109
* </pre>
* @param assetsDirPath assets dir path
* @return
*/
def genBuiltinPluginList(String assetsDirPath) {
final File assetsDir = file(assetsDirPath)
final Pattern pattern = Pattern.compile(/(^[a-z]+(\.[a-z][a-z0-9]*)*)_(\d+\.\d+\.\d+)\.apk$/)
def result = assetsDir.list().inject([]) { list, filename ->
def matcher = pattern.matcher(filename)
if (matcher.matches()) {
def packageName = matcher.group(1)
def versionName = matcher.group(3)
def versionCode = versionName.split(/\./).inject(0) { acc, val ->
acc * 100 + val.toInteger()
}
list << new Tuple(filename, packageName, versionName, versionCode)
} else {
list
}
}
File propertiesFile = new File(assetsDir, Globals.BUILTIN_PLUGIN_LIST_CSV_FILE)
if (propertiesFile.exists()) {
propertiesFile.delete()
}
propertiesFile.createNewFile()
propertiesFile.withPrintWriter('utf-8') { writer ->
println "[genBuiltinPluginList] ====== BEGIN: DUMP BUILT-IN PLUGIN LIST ======"
result.each {
println it.toString()
writer.println(it.join(','))
}
println "[genBuiltinPluginList] ====== END: DUMP BUILT-IN PLUGIN LIST ======"
}
}
// 导出方法 downloadPluginStableVersion 供其他 gradle 脚本调用
project.ext.downloadPluginStableVersion = this.&downloadPluginStableVersion
// 导出方法 downloadPluginSnapshotVersion 供其他 gradle 脚本调用
project.ext.downloadPluginSnapshotVersion = this.&downloadPluginSnapshotVersion
// 导出方法 genBuiltinPluginList 供其他 gradle 脚本调用
project.ext.genBuiltinPluginList = this.&genBuiltinPluginList
\ No newline at end of file
/*
* Copyright (C) 2017 贵阳货车帮科技有限公司
*/
/**
* 全局的版本定义
* 1. 构建工具链版本
* 2. 第三方依赖库版本
*/
ext {
// android build tools version
COMPILE_SDK_VERSION = 25
BUILD_TOOLS_VERSION = '25.0.3'
MIN_SDK_VERSION = 14
// gradle maven dependencies version
ANDROID_SUPPORT_LIB_VERSION = '25.3.1'
ANDROID_MULTIDEX_VERSION = '1.0.1'
JUNIT_VERSION = '4.12'
ANDROID_TEST_SUPPORT_VERSION = '0.5'
ESPRESSO_VERSION = '2.2.2'
UIAUTOMATOR_VERSION = '2.1.2'
GSON_VERSION = '2.8.1'
COMMONS_IO_VERSION = '1.4'
COMMONS_LANG_VERSION = '2.5'
HTTP_MIME_VERSION = '4.1.1'
JAVA_BASE64_VERSION = '1.3.1'
// 极光推送
JPUSH_VERSION = '2.1.3'
// 高徳地图
AMAP_MAP3D_VERSION = '4.1.1'
AMAP_LOCATION_VERSION = '3.3.0'
AMAP_SEARCH_VERSION = '5.0.0'
AWESOMELOG_VERSION = '1.0.1'
PROTOBUF_JAVA_VERSION = '2.4.1'
// 二维码生成/扫描 ZXing https://github.com/zxing/zxing
ZXING_VERSION = '3.1.0'
// 数据库 ORM 框架 DBFlow https://github.com/Raizlabs/DBFlow
DBFLOW_VERSION = '3.0.0'
// 内存泄漏检测 LeakCanary https://github.com/square/leakcanary
LEAK_CANARY_VERSION = '1.5'
// mockito
MOCKITO_CORE = '2.8.47'
// assertj
ASSERTJ_CORE = '3.8.0'
ASSERTJ_ANDROID = '1.1.1'
// Robolectric
ROBOLECTRIC_VERSION = '3.3.2'
//Okhttp
OKHTTP3_VERSION = '3.9.0'
//retrofit
RETROFIT2_VERSION = '2.3.0'
//rxjava
RXJVA_VERSION = '2.1.3'
RXANDROID_VERSION = '2.0.1'
// http://nexus.56qq.cn:81/content/repositories/wlqq-releases/com/wlqq/android/ImageLoader/
IMAGE_LOADER_VERSION = '1.0.0'
// http://nexus.56qq.cn:81/content/repositories/wlqq-snapshots/com/wlqq/android/phantom-compiler/
PHANTOM_COMPILER_VERSION = '0.5.0-SNAPSHOT'
//powermock
PROWEMOCK_VERSIN = '1.7.3'
// https://mvnrepository.com/artifact/org.json/json
ORG_JSON_VERSION = '20160810'
// https://mvnrepository.com/artifact/com.google.code.findbugs/findbugs-annotations
FINDBUGS_ANNOTATIONS_VERSION = '3.0.1'
// 宿主共享公共库最小版本,为了向前兼容,这个版本通常不需要修改
MIN_ANDROID_SUPPORT_LIB_VERSION = '25.3.1'
MIN_GSON_VERSION = '2.8.1'
MIN_COMMONS_IO_VERSION = '1.4'
MIN_COMMONS_LANG_VERSION = '2.5'
MIN_HTTP_MIME_VERSION = '4.1.1'
MIN_JAVA_BASE64_VERSION = '1.3.1'
MIN_IMAGE_LOADER_VERSION = '1.0.0'
}
/**
* 获取 Jenkins Job Build Number,若没有在 Jenkins 编译,则返回零
*
* @return Jenkins Job Build Number,若没有在 Jenkins 编译,则返回零
*/
def static getJenkinsBuildNumber() {
def env = System.env
if (env == null || !env.containsKey('BUILD_NUMBER')) {
return 0
}
return env.BUILD_NUMBER
}
/**
* 是否在 Jenkins 上编译
*
* @return true 表示在 Jenkins 上编译;否则 false
*/
def static isBuildOnJenkins() {
return getJenkinsBuildNumber() > 0
}
// 将方法导出为全局方法
ext {
getJenkinsBuildNumber = this.&getJenkinsBuildNumber
isBuildOnJenkins = this.&isBuildOnJenkins
}
\ No newline at end of file
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
#org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
#并行编译
org.gradle.parallel=true
#配置内存
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#守护进程
org.gradle.daemon=true
#android.enableAapt2=false
Set<String> findDependencies(String type) {
Set<String> dependenceLibs = []
rootProject.allprojects.each {
try {
it.configurations.getByName(type)
} catch (UnknownConfigurationException e) {
return;
}
Iterator<Dependency> iterator = it.configurations.getByName(type).dependencies.iterator()
while (iterator.hasNext()) {
Dependency dependency = iterator.next()
if (null != dependency.group && !"unspecified".equals(dependency.version)) {
dependenceLibs.add("${dependency.group}:${dependency.name}:${dependency.version}")
}
}
}
return dependenceLibs
}
/**
* 生成依赖库版本描述文件
*
* @param dependenceLibs 依赖库集合,集合元素以依赖库 maven GAV 格式描述描述
* @param outputDir 文件输出目录
* @param fileName 文件名
*/
void createPropertiesFile(Set<String> dependenceLibs, String outputDir, String fileName) {
File dir = new File(outputDir)
if (dir.isFile()) {
throw new GradleException("[createPropertiesFile] the specified dir: ${outputDir} must not be a file")
}
if (!dir.exists() && !dir.mkdirs()) {
throw new GradleException("[createPropertiesFile] create dir: ${outputDir} failed")
}
File propertiesFile = new File(outputDir, fileName)
propertiesFile.withWriter('UTF-8') { writer ->
println "[createPropertiesFile: ${fileName}] ====== BEGIN DUMP ======"
dependenceLibs.each {
// write to file
writer.writeLine(it)
// dump to console
println it
}
println "[createPropertiesFile: ${fileName}] ====== END DUMP ======"
}
}
void createCompileProperties(String outputDir) {
createPropertiesFile(findDependencies('compile'), outputDir, 'compile_dependencies.txt')
}
/**
* Create lib requirements file declared by plugin
* <ul>
* <li>provided_dependencies.txt for Phantom version lower than 0.6.0</li>
* <li>provided_dependencies_v2.txt for Phantom version greater or equal than 0.6.0</li>
* </ul>
*
* @param outputDir the output directory
*
* @see <a href="http://git.56qq.com/Android-Team/WLExcludeClasses/blob/master/wl-plugin-exclude/src/main/groovy/com/wlqq/gradle/plugin/exclude/ExcludeClasses.groovy">ExcludeConfig</a>
*/
void createProvidedProperties(String outputDir) {
def providedLibs = findDependencies('provided')
def providedLibsV2 = new HashSet(providedLibs)
def excludes = project.extensions.findByName("wlExclude")
if (null != excludes) {
def compileLibs = findDependencies('compile')
// excludeLib type : ExcludeConfig
for (def excludeLib : excludes.excludeLibs) {
compileLibs.each { compileLib ->
if (compileLib == excludeLib.name) {
if (!isVersionRequirementValid(excludeLib.versionRequirement)) {
throw new GradleException("version requirement invalid: '${excludeLib.versionRequirement}'")
}
providedLibs.add("${excludeLib.groupId}:${excludeLib.artifactId}:${stripOperator(excludeLib.versionRequirement)}")
providedLibsV2.add("${excludeLib.groupId}:${excludeLib.artifactId}:${excludeLib.versionRequirement}")
}
}
}
}
createPropertiesFile(providedLibs, outputDir, 'provided_dependencies.txt')
createPropertiesFile(providedLibsV2, outputDir, 'provided_dependencies_v2.txt')
}
static boolean isVersionRequirementValid(String versionRequirement) {
// 合法的 versionRequirement 声明为 4.12 或 >=4.12
return versionRequirement ==~ /(?:>=)?(:?\d+\.)*\d+/
}
static String stripOperator(String versionRequirement) {
return versionRequirement.replaceFirst(">=", "")
}
//生成compile_dependencies.txt属性文件
//调用方式project.ext.createCompileProperties()
project.ext.createCompileProperties = this.&createCompileProperties
//生成provided_dependencies.txt属性文件
//调用方式project.ext.createProvidedProperties()
project.ext.createProvidedProperties = this.&createProvidedProperties
\ No newline at end of file
/**
* 该脚本创建了用于上传构件(jar/aar,源代码,Javadoc 文档)的任务 <code>uploadArchives</code>
* 默认上传到 snapshots 仓库,若指定可选参数 <code>release</code> 则上传到 releases 仓库
* <p>
* 上传构件需要的 Nexus username 和 password 需要以 gradle properties 的方式指定
* </p>
*/
apply plugin: 'maven'
def nexusUrl = 'http://nexus.56qq.cn:81'
/**
* 获取 Nexus username, 建议配置到 global gradle properties (~/.gradle/gradle.properties)
*
* @return Nexus username
*/
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
/**
* 获取 Nexus password, 建议配置到 global gradle properties (~/.gradle/gradle.properties)
*
* @return Nexus password
*/
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
/**
* 是否上传到 releases 仓库,通过 gradle 命令行参数 <code>-Prelease</code> 指定
*
* @return true 上传到 releases 仓库,否则 false
*/
def isRelease() {
return hasProperty('release')
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
pom.name = project.name
pom.groupId = 'com.wlqq.android' // Android Team 统一使用 Group Id: com.wlqq.android
pom.artifactId = project.name // ArtifactId 为 project 的名字
if (isRelease()) {
pom.version = android.defaultConfig.versionName
} else {
pom.version = android.defaultConfig.versionName + '-SNAPSHOT'
}
// 稳定发布版仓库
repository(url: "${nexusUrl}/content/repositories/wlqq-releases") {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
// 开发快照版仓库
snapshotRepository(url: "${nexusUrl}/content/repositories/wlqq-snapshots") {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
}
}
}
// 生成 Javadoc
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
// 打包 Javadoc
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
// 打包源代码
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
}
}
\ No newline at end of file
/**
* 该脚本创建了用于上传 java 项目生成的构件(jar/源代码/Javadoc)的任务 <code>uploadArchives</code>
* <p>
* 默认上传到 snapshots 仓库,若指定可选参数 <code>release</code> 则上传到 releases 仓库
* </p>
*
* <p>
* <b>注意</b>
* <ul>
* <li>上传构件需要的 Nexus username 和 password 需要在 <code>gradle.properties</code> 中定义</li>
* <li>项目的 POM_ARTIFACT_ID 和 POM_VERSION_NAME 需要在 <code>gradle.properties</code> 中定义</li>
* </ul>
* </p>
*/
apply plugin: 'maven'
def nexusUrl = 'http://nexus.56qq.cn:81'
/**
* 获取 Nexus username, 建议配置到 global gradle properties (~/.gradle/gradle.properties)
*
* @return Nexus username
*/
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
/**
* 获取 Nexus password, 建议配置到 global gradle properties (~/.gradle/gradle.properties)
*
* @return Nexus password
*/
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
/**
* 是否上传到 releases 仓库,通过 gradle 命令行参数 <code>-Prelease</code> 指定
*
* @return true 上传到 releases 仓库,否则 false
*/
def isRelease() {
return hasProperty('release')
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
pom.name = project.name
// Android Team 统一使用 Group Id: com.wlqq.android
pom.groupId = 'com.wlqq.android'
// POM_ARTIFACT_ID 需要在 apply 该脚本的模块的 gradle.properties 中定义
pom.artifactId = POM_ARTIFACT_ID
// POM_VERSION_NAME 需要在 apply 该脚本的模块的 gradle.properties 中定义
if (isRelease()) {
pom.version = POM_VERSION_NAME
} else {
pom.version = "${POM_VERSION_NAME}-SNAPSHOT"
}
// 稳定发布版仓库
repository(url: "${nexusUrl}/content/repositories/wlqq-releases") {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
// 开发快照版仓库
snapshotRepository(url: "${nexusUrl}/content/repositories/wlqq-snapshots") {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
}
}
}
}
// 打包源代码
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
}
artifacts {
archives sourcesJar
}
\ 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