-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
171 lines (153 loc) · 8.08 KB
/
build.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: 'config.gradle'
repositories {
maven { url = 'https://maven.aliyun.com/repository/google' }
maven { url = 'https://maven.aliyun.com/repository/central' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
name 'maven-snapshot'
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
maven { url = 'https://maven.aliyun.com/repository/google' }
maven { url = 'https://maven.aliyun.com/repository/public' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
file('local.properties').withInputStream { input ->
ext.localProps = new Properties().with(true) { it.load(input) }
}
subprojects {
project.afterEvaluate {
task artifactSourcesJar(type: Jar) {
if (project.hasProperty('android')) {
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
archiveClassifier.set("sources")
}
group 'cn.alvince.zanpakuto'
if (project.plugins.hasPlugin('com.android.library')) {
project.pluginManager.apply('maven-publish')
project.ext.propFromConfigOrEnv = { name ->
def value = rootProject.ext.localProps.getProperty(name)
if (value != null && !value.empty) return value
value = project.getProperty(name)
if (value != null && !value.empty) return value
value = System.getenv(name)
return value != null ? value : ""
}
project.android.buildFeatures {
buildConfig false
}
publishing {
def mvnConfig = project.extensions.getByName('mvn')
def confVersion = mvnConfig.version
def artVersion = confVersion.isEmpty() ? project.version : confVersion
println "artifact version: $artVersion"
publications {
maven(MavenPublication) {
artifactId mvnConfig.artifact
groupId mvnConfig.group
version artVersion
artifact project.file("build/outputs/aar/${project.name}-release.aar")
artifact artifactSourcesJar
pom {
name = mvnConfig.name
packaging = mvnConfig.packaging
description = mvnConfig.description
url = 'https://github.com/alvince/android-zanpakuto'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'alvince'
name = 'Alvince'
email = '[email protected]'
}
}
}
pom.withXml {
def root = asNode()
def dependenciesNode = root.appendNode('dependencies')
ext.addDependency = { Dependency dep, String cat ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") {
return // invalid dependencies should be ignored
}
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('version', dep.version)
if (cat.contains('compile') || cat.contains('implementation')) {
dependencyNode.appendNode('scope', 'runtime')
}
println("$cat > ${dep.group}:${dep.name}:${dep.version}")
// Some dependencies may have types, such as aar, that should be mentioned in the POM file
def artifactsList = dep.properties['artifacts']
if (artifactsList != null && artifactsList.size() > 0) {
final artifact = artifactsList[0]
dependencyNode.appendNode('type', artifact.getType())
}
if (!dep.transitive) {
// In case of non transitive dependency, all its dependencies should be force excluded from them POM file
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
// For transitive with exclusions, all exclude rules should be added to the POM file
final exclusions = dependencyNode.appendNode('exclusions')
dep.properties.excludeRules.each { ExcludeRule rule ->
final exclusionNode = exclusions.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
configurations.all { configuration ->
if (configuration.name in ['compileOnly', 'api', 'implementation', 'runtime']) {
configuration.dependencies.each { addDependency(it, configuration.name) }
}
}
}
}
}
repositories {
def repoUsername = project.propFromConfigOrEnv('ossrhUsername')
def repoPassword = project.propFromConfigOrEnv('ossrhPassword')
if (repoUsername.isEmpty() || repoPassword.isEmpty()) {
throw new IllegalStateException("Should set properties ossrhUsername and ossrhPassword")
}
println "credentials: username[$repoUsername], password[$repoPassword]"
maven {
def releasesRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/releases/'
def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
url = artVersion.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
println "use url: $url"
credentials {
username = repoUsername
password = repoPassword
}
}
}
}
}
}
}