forked from TradeMe/MapMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publishing.gradle
116 lines (99 loc) · 3.57 KB
/
publishing.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
project.afterEvaluate {
if (project.plugins.hasPlugin("com.android.library")) {
project.android.libraryVariants.all { variant ->
variant.getOutputs().each { output ->
def outputFile = output.outputFile;
def newName = "${project.name}-v${project.version}.aar"
output.outputFile = new File(outputFile.parentFile, newName);
}
}
}
}
project.group = project.ext.group
project.version = project.ext.version
bintray {
user = project.hasProperty("BINTRAY_USERNAME") ? project.property('BINTRAY_USERNAME') : null
key = project.hasProperty("BINTRAY_API_KEY") ? project.property('BINTRAY_API_KEY') : null
pkg {
repo = 'MapMe'
name = getArtifactId()
userOrg = 'trademe'
licenses = ['Apache-2.0']
vcsUrl = project.ext.scm
version {
name = project.version
desc = project.ext.description
released = new Date()
vcsTag = project.version
}
publications = ['Bintray']
}
}
// Create the pom configuration:
def pomConfig = {
licenses {
license {
name "MIT License"
url "http://www.opensource.org/licenses/mit-license.php"
distribution "repo"
}
}
scm {
url ext.scm
}
}
//create a jar from source files
task sourceJar(type: Jar) {
if (project.plugins.hasPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
}
publishing.publications {
Bintray(MavenPublication) {
groupId project.ext.group
artifactId getArtifactId()
version project.ext.version
artifact sourceJar
artifact "$buildDir/outputs/aar/${project.name}-v${project.version}.aar"
//generate pom nodes for dependencies
//when a project references another project, it's artifact node is generated
pom.withXml {
def root = asNode()
root.appendNode('description', project.ext.description)
root.appendNode('name', project.ext.name)
root.appendNode('url', project.ext.scm)
root.children().last() + pomConfig
def dependenciesNode = root.appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
if (dependency.group != null && dependency.name != null) {
if (dependency instanceof ProjectDependency) {
dependency.getDependencyProject().getArtifacts().each { artifact ->
addDependencyNodeToPom(dependenciesNode, dependency.group, getArtifactId(dependency.dependencyProject), dependency.version)
}
} else {
addDependencyNodeToPom(dependenciesNode, dependency.group, dependency.name, dependency.version)
}
}
}
}
}
}
def getArtifactId() {
return getArtifactId(project)
}
def getArtifactId(someProject) {
if (!someProject.ext.has('artifactId')) {
//default artifactId is the project/module name
return someProject.getName();
}
return someProject.ext.artifactId;
}
def addDependencyNodeToPom(dependenciesNode, group, artifact, version) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode("groupId", group)
dependencyNode.appendNode("artifactId", artifact)
dependencyNode.appendNode("version", version)
}