-
Notifications
You must be signed in to change notification settings - Fork 1
/
maven-publish.gradle
142 lines (122 loc) · 5.12 KB
/
maven-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
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
//https://github.com/kaedea/publication/blob/develop/gradle/maven-publish.gradle
// Generate aar and upload to maven repo.
apply plugin: 'maven-publish'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk-core:1.11.5' // Gradle build dependency, not app dependency
}
}
import com.amazonaws.auth.*
// thanks to Matthieu Vachon and Josh Hickman at https://discuss.gradle.org/t/s3-awscredentials-should-be-able-to-load-from-an-aws-profile-file/8782/9
def fetchAwsCredentials = {
try {
return new DefaultAWSCredentialsProviderChain().getCredentials()
} catch (Exception e) {
println("Unable to get credentials: " + e.getMessage())
}
}
AWSCredentials awsCredentials = fetchAwsCredentials()
publishing {
publications {
debugAar(MavenPublication) {
// 1. Config artifact id
groupId rootProject.ext.group
artifactId rootProject.ext.artifact
version = rootProject.ext.version + '-debug'
ext.build = 'debug'
artifact bundleDebug
}
releaseAar(MavenPublication) {
// 1. Config artifact ids
groupId rootProject.ext.group
artifactId rootProject.ext.artifact
version = rootProject.ext.version
ext.build = 'release'
// 2. Config archives:
// aar, source.jar, javadoc.jar ...
artifact bundleRelease
artifact androidSourcesJar
//artifact androidJavadocsJar
// generate pom nodes for dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.getByName("archives").getAllDependencies().each { dependency ->
if (dependency.group != null && (dependency.name != null || "unspecified".equals(dependency.name)) && dependency.version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
dependencyNode.appendNode('groupId', dependency.group)
// Exclusions (transitive dependencies of the current dependency)
if (!dependency.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
final exclusionNode = node.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dependency.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
final exclusionNode = node.appendNode('exclusions').appendNode('exclusion')
dependency.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
}
}
}
}
repositories {
maven {
name = 'release'
url "s3://polarbear-artifacts.s3.amazonaws.com/releases"
credentials(AwsCredentials) {
if (awsCredentials != null) {
accessKey awsCredentials.getAWSAccessKeyId()
secretKey awsCredentials.getAWSSecretKey()
}
}
}
mavenLocal()
}
}
// Remove weird task combinations such as publishDebugToReleaseRepository
afterEvaluate {
tasks.withType(PublishToMavenLocal) { task ->
if (task.publication.hasProperty('build')
&& (task.publication.build == 'release'
|| (task.publication.hasProperty('build')
&& task.publication.hasProperty('repository')
&& task.publication.build != task.repository.name))) {
task.enabled = false
task.group = null
}
}
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
excludes = ['**/*.md', '**/*.kt'] // < ---- Exclude Markdown and Kotlin files from javadocs
// don't complain rn
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}