-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
129 lines (109 loc) · 4.43 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
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import static de.fayard.refreshVersions.core.Versions.versionFor
buildscript {
ext {
publishBuildVariant = "release"
}
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
// NOTE: These are dependencies for the build script itself
// Do not place your application dependencies here;
// they belong in the individual module build.gradle files
classpath Android.tools.build.gradlePlugin
classpath Kotlin.gradlePlugin
classpath "org.jetbrains.dokka:dokka-gradle-plugin:_"
classpath "org.jlleitschuh.gradle:ktlint-gradle:_"
}
}
plugins {
//Project-wide dependencies
id "org.jetbrains.dokka"
id "org.jlleitschuh.gradle.ktlint"
}
dependencies {
dokkaHtmlMultiModulePlugin "org.jetbrains.dokka:versioning-plugin:_"
}
tasks.register("clean", Delete) {
delete rootProject.layout.buildDirectory
}
static def readXmlValue(String filePath, String tagName, Project project) {
def xmlFile = new File(project.projectDir, filePath)
// Check if the file exists
if (!xmlFile.exists()) {
throw new FileNotFoundException("The XML file does not exist: ${xmlFile.absolutePath}")
}
// Parse the XML file
def xmlContent
try {
xmlContent = new XmlSlurper().parse(xmlFile)
} catch (Exception e) {
throw new RuntimeException("Failed to parse XML file: ${xmlFile.absolutePath}. Error: ${e.message}", e)
}
// Look for the string with the specific name attribute
def result = xmlContent.'string'.find { it.@name == tagName }
if (result == null) {
throw new IllegalArgumentException("No string found with the name '${tagName}' in the file: ${xmlFile.absolutePath}")
}
return result.text()
}
dokkaHtmlMultiModule {
def versionName = readXmlValue('sdk/core/src/main/res/values/strings.xml','klaviyo_sdk_version_override', project)
def oldVersionsDir = layout.buildDirectory.dir("../docs/")
outputDirectory = layout.buildDirectory.dir("../docs/${versionName}")
includes.from("README.md")
String versioningConfiguration = """
{
"version": "${versionName}",
"olderVersionsDir": "${oldVersionsDir}"
}
"""
pluginsMapConfiguration.set(
["org.jetbrains.dokka.versioning.VersioningPlugin": versioningConfiguration]
)
}
/**
* Command to bump the version of the project
* including updating README and documentation references
*/
public class BumpVersion extends DefaultTask {
private String nextVersion;
@Option(option = "nextVersion", description = "New semantic version number")
public void setNextVersion(String nextVersion) {
this.nextVersion = nextVersion;
}
@Input
public String getNextVersion() {
return nextVersion;
}
static String readXmlValue(String filePath, String tagName) {
def xmlFile = new File(filePath)
def xmlContent = new XmlSlurper().parse(xmlFile)
// Look for the string with the specific name attribute
def result = xmlContent.'string'.find { it.@name == tagName }
return result?.text() ?: ""
}
@TaskAction
public void bumpVersion() {
def currentVersion = readXmlValue('sdk/core/src/main/res/values/strings.xml','klaviyo_sdk_version_override')
println(currentVersion)
def nextVersion = this.getNextVersion()
def currentBuild = versionFor(project, "version.klaviyo.versionCode") as Integer
def nextBuild = currentBuild + 1
print("Changing semantic version number from $currentVersion to $nextVersion\n")
print("Auto-incrementing version code from $currentBuild to $nextBuild\n")
ant.replace(file:"versions.properties", token:"versionCode=$currentBuild", value:"versionCode=$nextBuild")
def file = new File('sdk/core/src/main/res/values/strings.xml')
def newName = file.text.replace(currentVersion,nextVersion)
file.text = newName
ant.replace(file:"README.md", token:"analytics:$currentVersion", value:"analytics:$nextVersion")
ant.replace(file:"README.md", token:"push-fcm:$currentVersion", value:"push-fcm:$nextVersion")
ant.replace(file:"docs/index.html", token:"$currentVersion", value:"$nextVersion")
}
}
tasks.register("bumpVersion", BumpVersion)