forked from codyer/ElegantBus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-local-aar-maven.gradle
87 lines (84 loc) · 4.15 KB
/
config-local-aar-maven.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* ************************************************************
* 文件:config-local-aar-maven.gradle 模块:ElegantBus 项目:ElegantBus
* 当前修改时间:2020年06月17日 22:43:58
* 上次修改时间:2020年06月17日 22:38:02
* 作者:Cody.yi https://github.com/codyer
*
* 描述:ElegantBus
* Copyright (c) 2020
* ************************************************************
*/
apply plugin: 'maven'
def groupId = LOCAL_GROUP_ID + '.' + this.parent.getName()
// 包含变体的 aar 上传
uploadArchives() {
repositories {
mavenDeployer {
repository(url: LOCAL_REPOSITORY)
if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
if (variant.name.toLowerCase().contains("debug")) {
return
}
def isFlavor = !variant.flavorName.isEmpty()
def flavorName = "${variant.flavorName}"
// 生成多个pom
addFilter(flavorName) { artifact, file ->
true
}
/*
// 生成 source 文件
def sourcesJarTask = project.tasks.create "sourcesJar${variant.name.capitalize()}", Jar
variant.sourceSets.each {
if (it.name == "main" || it.name == variant.flavorName)
sourcesJarTask.from it.java.sourceFiles
}
artifacts {
archives(sourcesJarTask.archivePath) {
classifier variant.flavorName + "-sources"
builtBy sourcesJarTask
name = project.name
}
}
*/
pom(flavorName).groupId = groupId
pom(flavorName).artifactId = this.parent.getName() + '-' + this.getName() + "-" + flavorName
pom(flavorName).version = rootProject.ext.componentVersion // 版本号
pom(flavorName).packaging = 'aar'
// 自定义pom的依赖集
pom(flavorName).withXml {
def root = asNode()
def dependencyNodes = root["dependencies"][0] ?: root.appendNode("dependencies")
def addDep = {
if (it.group == null) return // Avoid empty dependency nodes
def dependencyNode = dependencyNodes.appendNode('dependency')
if (it.version == "unspecified") {
dependencyNode.appendNode('groupId', groupId)
dependencyNode.appendNode('artifactId', this.parent.getName() + '-' + it.name)
dependencyNode.appendNode('version', rootProject.ext.componentVersion)
} else {
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
if (it.hasProperty('optional') && it.optional) {
dependencyNode.appendNode('optional', 'true')
}
}
// 添加基本依赖
// configurations.api.allDependencies.each addDep
configurations.implementation.allDependencies.each addDep
// 添加特殊依赖
if (isFlavor) {
configurations["${flavorName}Implementation"].allDependencies.each addDep
configurations["${flavorName}Implementation"].allDependencies.each addDep
configurations["${flavorName}Api"].allDependencies.each addDep
configurations["${flavorName}Api"].allDependencies.each addDep
}
}
}
}
}
}
}