-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.gradle
57 lines (49 loc) · 2.06 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
apply plugin: 'maven-publish'
ext {
localAARPublishConfig = [groupId: "local", version: "1.0"]
}
// Load local.properties if it is found
def propFile = file("${rootDir}/local.properties")
if (!propFile.exists()) propFile.createNewFile()
def props = new Properties()
propFile.withInputStream { props.load(it) }
//Give preference to command line params over local.properties
ext.useAAR = (hasProperty("useAAR")) ? getProperty("useAAR").toBoolean() : props.getProperty("useAAR", "false").toBoolean()
ext.inDevModules = (hasProperty("modules")) ? getProperty("modules").split(" ") : props.getProperty('modules', ":app").split(" ")
publishing {
publications {
aar(MavenPublication) {
project.tasks.publish.dependsOn("assembleDebug")
groupId localAARPublishConfig.groupId
artifactId project.name
version localAARPublishConfig.version
artifact("$buildDir/outputs/aar/${project.getName()}-debug.aar")
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each { addDependencyNode(dependencies, it) }
configurations.api.allDependencies.each { addDependencyNode(dependencies, it) }
}
}
}
repositories {
maven {
url = "$rootDir/mavenLocal"
}
project.tasks.publish.dependsOn("assembleDebug")
}
}
private void addDependencyNode(Node dependencies, Dependency it) {
if (it.group == null || it.group == localAARPublishConfig.groupId) {
println("ignoring dependency ${it.group}:${it.name}:${it.version}")
return
}
def dependency = dependencies.appendNode('dependency')
if (it.group == rootProject.name) {
dependency.appendNode('groupId', localAARPublishConfig.groupId)
dependency.appendNode('version', localAARPublishConfig.version)
} else {
dependency.appendNode('groupId', it.group)
dependency.appendNode('version', it.version)
}
dependency.appendNode('artifactId', it.name)
}