forked from byhook/merge-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.gradle
77 lines (67 loc) · 3.27 KB
/
publish.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
////////////////////////////////////////////
//////////// MAVEN PUBLISHING //////////////
////////////////////////////////////////////
apply plugin: 'maven-publish'
publishing {
publications {
androidLibs(MavenPublication) {
groupId = GROUP
artifactId POM_ARTIFACT_ID
version = VERSION_NAME
artifact "${project.buildDir}/outputs/aar/${getArtifactFileName()}" //bundleRelease
List<String> embedList = new ArrayList<>();
Map<String, ResolvedDependency> depList = new LinkedHashMap<>();
//List all embedded dependencies
configurations.embedded.allDependencies.each {
def depName = String.format("%s:%s", it.group, it.name)
embedList.add(depName);
}
//Collect all first level dependencies except embedded ones
configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
ResolvedDependency dep ->
def depName = String.format("%s:%s", dep.moduleGroup, dep.moduleName)
if (!embedList.contains(depName) && !depList.containsKey(depName)) {
depList.put(depName, dep)
}
}
//Collect all second level dependencies of embedded ones
configurations.embedded.resolvedConfiguration.firstLevelModuleDependencies.each {
//Second Level Depenencies
it.children.each {
ResolvedDependency dep ->
def depName = String.format("%s:%s", dep.moduleGroup, dep.moduleName)
if (!embedList.contains(depName) && !depList.containsKey(depName)) {
depList.put(depName, dep)
}
}
}
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
depList.values().each {
ResolvedDependency dep ->
def hasGroup = dep.moduleGroup != null
def hasName = (dep.moduleName != null && !"unspecified".equals(dep.moduleName) && !"".equals(dep.moduleVersion))
def hasVersion = (dep.moduleVersion != null && !"".equals(dep.moduleVersion) && !"unspecified".equals(dep.moduleVersion))
if (hasGroup && hasName && hasVersion) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.moduleGroup)
dependencyNode.appendNode('artifactId', dep.moduleName)
dependencyNode.appendNode('version', dep.moduleVersion)
}
}
}
}
}
repositories {
maven {
//远程maven仓库的地址如: http://127.0.0.1:8081/nexus/content/repositories/releases
url uri("/home/byhook/android/maven")
//远程仓库需要配置密钥
/*credentials {
username "admin"
password "haoadmin"
}*/
}
}
}