-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathbuild.gradle
More file actions
83 lines (74 loc) · 2.67 KB
/
build.gradle
File metadata and controls
83 lines (74 loc) · 2.67 KB
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
import java.util.regex.Pattern
plugins {
id 'base'
id 'org.jreleaser' version '1.18.0'
}
jreleaser {
project {
}
signing {
active = 'ALWAYS'
armored = true
}
deploy {
maven {
mavenCentral {
sonatype {
/** Warning: In your JReleaser config file set
* JRELEASER_MAVENCENTRAL_STAGE to 'UPLOAD' in order to
* prevent the deployment from automatically publishing
* without any UI intervention. */
active = 'NEVER'
url = 'https://central.sonatype.com/api/v1/publisher'
stagingRepository(layout.buildDirectory.dir("staging-deploy").get().toString())
stage = 'UPLOAD'
}
}
release {
github {
skipRelease = true
skipTag = true
}
}
}
}
}
/** Defines a custom task for updating version numbers. */
abstract class UpdateVersionTask extends DefaultTask {
static final def VERSION_REGEX = "([0-9]+)\\.([0-9]+)\\.([0-9]+)(-SNAPSHOT)?"
@Input
String newVersion
@InputFile
File propertiesFile = project.file("${project.projectDir}/gradle.properties")
@TaskAction
def update() {
if (newVersion == null) {
throw new GradleException("Need to specify newVersion")
}
if (propertiesFile == null) {
throw new GradleException("Need to specify gradlePropertiesFile")
}
if (!newVersion.matches(VERSION_REGEX)) {
throw new GradleException("Invalid format for -PnewVersion. Expecting: ${VERSION_REGEX}")
}
def toSet = new Properties()
propertiesFile.withInputStream { toSet.load(it) }
toSet.version = newVersion
propertiesFile.withOutputStream { toSet.store(it, "See LICENSE for license terms") }
}
}
/** Updates the version to version specified with -PnewVersion=foo. */
task updateVersion(type: UpdateVersionTask) {
newVersion = project.properties.newVersion
}
/** Updates the version to the next snapshot. */
task updateVersionToNextSnapshot(type: UpdateVersionTask) {
def current = new Properties()
propertiesFile.withInputStream { current.load(it) }
def matcher = Pattern.compile(VERSION_REGEX).matcher(current.version)
if (!matcher.find()) {
throw new GradleException("Current version cannot be parsed: ${current.version} expected match of: ${VERSION_REGEX}")
}
def toSet = "${matcher.group(1)}.${matcher.group(2)}.${Integer.parseInt(matcher.group(3)) + 1}-SNAPSHOT"
newVersion = toSet
}