-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish-base.gradle
75 lines (62 loc) · 2.46 KB
/
publish-base.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
import groovy.xml.QName
def VERSION_NAME = rootProject.ext.VERSION_NAME
def GROUP = rootProject.ext.GROUP
ext.POM_ARTIFACT_ID = project.name
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.javadocDeps
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
def configureDependencies(Dependency dep, Node dependenciesNode) {
if (dep.group != null && dep.name != null) {
def depGroup = dep.group
def depVersion = dep.version
if (depGroup.equalsIgnoreCase(rootProject.name)) {
depGroup = GROUP
depVersion = VERSION_NAME
}
println "Appending to POM -> $depGroup:${dep.name}:$depVersion"
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', depGroup)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', depVersion)
}
}
afterEvaluate {
publishing.publications {
"${POM_ARTIFACT_ID}"(MavenPublication) {
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
logging.captureStandardOutput LogLevel.INFO
println "Configuring POM file"
Node dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
Set<Dependency> dependencySet = new LinkedHashSet<>()
dependencySet += configurations.api.allDependencies
dependencySet += configurations.implementation.allDependencies
dependencySet += configurations.compile.allDependencies
dependencySet.each {
configureDependencies(it, dependenciesNode)
}
println "Done configuring POM file"
}
artifactId = POM_ARTIFACT_ID
groupId = GROUP
version = VERSION_NAME
artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
}
}
}