forked from tunjid/Android-Extensions
/
androidLib.gradle
145 lines (126 loc) · 4.53 KB
/
androidLib.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply from: "${project.rootDir}/version.gradle"
android {
compileSdkVersion parent.ext.compileSdkVersion
buildToolsVersion parent.ext.buildToolsVersion
defaultConfig {
minSdkVersion parent.ext.minSdkVersion
targetSdkVersion parent.ext.targetSdkVersion
consumerProguardFiles 'proguard-rules.pro'
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = "${project.getName()}-${project.version}.aar"
}
}
afterEvaluate {
def debugFile = file("$buildDir/outputs/aar/${project.getName()}-release.aar")
tasks.named("assembleRelease").configure {
doLast {
debugFile.renameTo("$buildDir/outputs/aar/${project.getName()}-${project.version}.aar")
}
}
}
}
bintray {
user = parent.ext.bintrayUser
key = parent.ext.bintrayApiKey
// jFrog plugin must be declared for this line to work
configurations = ['archives']
publications = ['lib']
// Package info for BinTray
pkg {
repo = 'maven'
name = 'android-extensions'
userOrg = user
licenses = ['MIT']
vcsUrl = 'https://github.com/tunjid/android-bootstrap.git'
version {
name = project.version
desc = 'An Android library to bootstrap an Android application.'
vcsTag = 'vx1.0.0-alpha01'
}
}
}
publishing {
publications {
lib(MavenPublication) {
// Default to command line arg before reading from from version.gradle
version = project.hasProperty('publish_version') ? "$publish_version" : project.version
groupId parent.ext.groupId // from parent root.gradle ext
artifactId project.getName()
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-${project.version}.aar")
// Add sources too
afterEvaluate {
artifact(sourcesJar) {
classifier = 'sources'
extension = 'jar'
}
}
//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 (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
if (it.group != null && it.name != null && it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
repositories {
maven {
name = parent.ext.publishRepoName
url = parent.ext.publishUrl
credentials {
username = parent.ext.publishUserName
password = parent.ext.publishPassword
}
}
parent.ext.publishRepositories.each { repo ->
def props = (repo as ConfigObject).toProperties()
maven {
name = props['name']
url = props['url']
credentials {
username = props['credentials.username']
password = props['credentials.password']
}
}
}
}
}
// Gradle task to generate sources after building a release aar
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease') {
task.dependsOn 'sourcesJar'
}
}