-
Notifications
You must be signed in to change notification settings - Fork 435
/
publish.gradle
72 lines (64 loc) · 2.97 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
////////////////////////////////////////////
//////////// MAVEN PUBLISHING //////////////
////////////////////////////////////////////
apply plugin: 'maven-publish'
publishing {
publications {
androidLibs(MavenPublication) {
artifact 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')
//Iterate over the compile dependencies, adding a <dependency> node for each
depList.values().each {
ResolvedDependency dep ->
def hasGroup = dep.moduleGroup != null
def hasName = (dep.moduleName != null || "unspecified".equals(dep.moduleName))
def hasVersion = dep.moduleVersion != null
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 {
url "/tmp/releases"
// url "http://myserver/maven"
credentials {
username nexus_user
password nexus_pass
}
}
}
}