-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpublish.gradle
90 lines (82 loc) · 2.94 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
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
/**
* Script for publishing
* Source: https://getstream.io/blog/publishing-libraries-to-mavencentral-2021
*
*
* If executed locally, create a local.properties files in the root directory
* containing the required information below.
* The secretKeyRingFile should be in binary format, e.g. gpg --export-secret-keys ID > ID.gpg
* The PGP public key should be published, e.g. to https://keys.openpgp.org/
*/
// Create variables with empty default values
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables (e.g. for CI)
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
}
// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
// new sonatype infrastructure as of 2021-02-24
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
task updateVersionInReadme {
doLast {
ant.replaceregexp(match: '(eltos:simpledialogfragments:v?)\\d*(\\.\\d*)*', replace: '\\1'+VERSION, flags: 'g', byline: true) {
fileset(dir: '.', includes: 'README.md')
}
}
}
task gitCommitAndTagVersion {
doFirst {
grgit.add(patterns: ['docs/javadoc', 'README.md', 'build.gradle'])
grgit.commit(message: 'Release v'+VERSION, sign: false)
grgit.tag.add(name:'v'+VERSION)
}
}
task checkVersionAlreadyExists {
doFirst {
assert !grgit.tag.list().name.contains('v'+VERSION),
"Version ${VERSION} defined in build.gradle already exists!"
}
}
// Release pipeline
task postRelease {
dependsOn gitCommitAndTagVersion
}
task doRelease {
dependsOn 'simpledialogfragments:javadoc'
dependsOn 'simpledialogfragments:publishReleasePublicationToSonatypeRepository'
dependsOn updateVersionInReadme
finalizedBy postRelease
}
task preRelease {
dependsOn checkVersionAlreadyExists
finalizedBy doRelease
}
task release {
dependsOn preRelease
}