-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
mavencentral-publications.gradle
106 lines (99 loc) · 4.47 KB
/
mavencentral-publications.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
// This script is responsible for setting up the publications, so they are ready to be published
// to Maven Central and other repositories. Publishing to Maven Central is configured in
// `mavencentral-publish.gradle`. They are in separate files as the nexus publish plugin used
// to deploy to Maven Central can only be applied to top level projects.
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply from: buildscript.sourceFile.getParent() + "/" + "mavencentral-properties.gradle"
// The publications doesn't know about our AAR dependencies, so we have to manually add them to the pom
// Credit: http://stackoverflow.com/questions/24743562/gradle-not-including-dependencies-in-published-pom-xml
def createPomDependencies(configurationNames) {
return {
def dependenciesNode = asNode().appendNode('dependencies')
configurationNames.each { configurationName ->
configurations[configurationName].allDependencies.each {
// Also ignore `realm-library` because that is used by the Kotlin Extensions as
// a project dependency, but it is being written to the POM file in a wrong way.
// Instead we just ignore it as the Gradle Plugin makes sure it is always present.
if (it.group != null && it.name != null && it.name != 'realm-library') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
//If there are any exclusions in dependency
if (it.excludeRules.size() > 0) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
it.excludeRules.each { rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group)
exclusionNode.appendNode('artifactId', rule.module)
}
}
}
}
}
}
}
// TODO: Consider refactoring this. See https://github.com/realm/realm-java/pull/7327#discussion_r586281652
def populatePom(publication, pomName, pomDescription, pomDependencies = null) {
publication.pom {
name = "${pomName}"
description = "${pomDescription}"
url = 'https://docs.mongodb.com/realm'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
issueManagement {
system = 'github'
url = 'https://github.com/realm/realm-java/issues'
}
scm {
url = 'scm:https://github.com/realm/realm-java'
connection = 'scm:[email protected]:realm/realm-java.git'
developerConnection = 'scm:[email protected]:realm/realm-java.git'
}
developers {
developer {
name = 'Realm'
email = '[email protected]'
organization = 'MongoDB'
organizationUrl = 'https://www.mongodb.com'
}
}
}
if (pomDependencies) {
publication.pom.withXml(pomDependencies)
}
}
publishing {
repositories {
maven {
name = "MavenCentral"
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = rootProject.ext["ossrhUsername"]
password = rootProject.ext["ossrhPassword"]
}
}
}
}
signing {
required { signBuild }
def keyId = rootProject.ext["signing.keyId"]
def ringFile = rootProject.ext["signing.secretKeyRingFile"]
def password = rootProject.ext["signing.password"]
useInMemoryPgpKeys(keyId, ringFile, password)
sign publishing.publications
}
// Export methods so they are available in other gradle files
// https://stackoverflow.com/questions/18715137/extract-common-methods-from-gradle-build-script
ext {
createPomDependencies = this.&createPomDependencies
populatePom = this.&populatePom
}