-
-
Notifications
You must be signed in to change notification settings - Fork 790
/
build.gradle.kts
185 lines (158 loc) · 7.43 KB
/
build.gradle.kts
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import org.apache.tools.ant.filters.EscapeUnicode
import org.jetbrains.changelog.Changelog
import java.time.LocalDate
import java.time.ZoneId
import java.time.format.DateTimeFormatter
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.kover) // Gradle Kover Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
}
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
fun dateValue(pattern: String): String =
LocalDate.now(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ofPattern(pattern))
val autoSnapshotVersionEnv: Provider<Boolean> = environment("AUTO_SNAPSHOT_VERSION").map(String::toBoolean).orElse(true)
val snapshotVersionPart: Provider<String> = properties("autoSnapshotVersion")
.map(String::toBoolean)
.orElse(false)
.zip(autoSnapshotVersionEnv, Boolean::and)
.map { if (it) "SNAPSHOT.${dateValue("yyMMdd")}" else "" }
val preReleaseVersion: Provider<String> = properties("pluginPreReleaseVersion")
.flatMap { prv -> prv.takeIf(String::isNotBlank)?.let { provider { it } } ?: snapshotVersionPart }
val preReleaseVersionPart: Provider<String> = preReleaseVersion.map { prv ->
prv.takeIf(String::isNotBlank)?.let { "-$it" } ?: ""
}
val buildMetadataPart: Provider<String> = properties("pluginBuildMetadata")
.map { part -> part.takeIf(String::isNotBlank)?.let { "+$it" } ?: "" }
val pluginVersion: Provider<String> = properties("pluginMajorVersion").zip(preReleaseVersionPart, String::plus)
val fullPluginVersion: Provider<String> = pluginVersion.zip(buildMetadataPart, String::plus)
val versionRegex =
Regex("""^((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)${'$'}""")
if (!versionRegex.matches(fullPluginVersion.get())) {
throw GradleException("Plugin version '${fullPluginVersion.get()}' does not match the pattern '$versionRegex'")
}
val publishChannel: Provider<String> = preReleaseVersion.map { preReleaseVersion: String ->
preReleaseVersion.takeIf(String::isNotEmpty)?.split(".")?.firstOrNull()?.lowercase() ?: "default"
}
extra["pluginVersion"] = pluginVersion.get()
extra["pluginPreReleaseVersion"] = preReleaseVersion.get()
extra["fullPluginVersion"] = fullPluginVersion.get()
extra["publishChannel"] = publishChannel.get()
group = properties("pluginGroup").get()
version = fullPluginVersion.get()
repositories {
mavenLocal()
maven(url = "https://maven.aliyun.com/repository/public")
maven(url = "https://maven-central.storage-download.googleapis.com/repos/central/data/")
maven(url = "https://www.jetbrains.com/intellij-repository/releases")
maven(url = "https://jitpack.io")
mavenCentral()
}
dependencies {
implementation(libs.jsoup)
implementation(libs.dbutils)
implementation(libs.ideaCompat)
implementation(libs.websocket) { exclude(module = "slf4j-api") }
implementation(libs.mp3spi) { exclude(module = "junit") }
testImplementation(libs.junit)
}
// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
jvmToolchain(11)
}
// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
pluginName = properties("pluginName")
version = properties("platformVersion")
type = properties("platformType")
// Plugin Dependencies. Use `platformPlugins` property from the gradle.properties file.
plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
}
// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
header = provider { "${version.get()} (${dateValue("yyyy/MM/dd")})" }
groups.empty()
repositoryUrl = properties("pluginRepositoryUrl")
}
// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
kover {
reports {
total {
xml { onCheck = true }
html { onCheck = true }
}
}
}
tasks {
runIde {
systemProperty("idea.is.internal", true)
jvmArgs = listOf(
// Enable hotswap, requires JBR 17+ or JBR 11 with DCEVM, and run in debug mode.
"-XX:+AllowEnhancedClassRedefinition",
// Run the IDE in a specified language.
// "-Duser.language=en"
)
// Path to IDE distribution that will be used to run the IDE with the plugin.
// ideDir.set(File("path to IDE-dependency"))
}
buildSearchableOptions {
enabled = properties("intellij.buildSearchableOptions.enabled").map(String::toBoolean).getOrElse(true)
}
patchPluginXml {
version = fullPluginVersion
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
pluginDescription = projectDir.resolve("DESCRIPTION.md").readText()
// local variable for configuration cache compatibility
val changelog = project.changelog
// Get the latest available change notes from the changelog file
changeNotes = pluginVersion.map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}
// Validate plugin starting from version 2024.1 to save disk space
listProductsReleases {
sinceVersion = "2024.1"
}
signPlugin {
certificateChain = environment("CERTIFICATE_CHAIN")
privateKey = environment("PRIVATE_KEY")
password = environment("PRIVATE_KEY_PASSWORD")
}
publishPlugin {
dependsOn("patchChangelog")
token = environment("PUBLISH_TOKEN")
// pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel,
// When using a non-default release channel, IntelliJ Platform-Based IDEs users will need to add a
// new custom plugin repository to install your plugin from the specified channel. For example, if
// specified 'snapshot' as a release channel, then users will need to add the
// https://plugins.jetbrains.com/plugins/snapshot/list repository to install the plugin and receive updates.
// These channels are treated as separate repositories for all intents and purposes. Read more:
// https://plugins.jetbrains.com/docs/marketplace/custom-release-channels.html
// Snapshot repositories:
// https://plugins.jetbrains.com/plugins/snapshot/list
// https://plugins.jetbrains.com/plugins/snapshot/8579
channels = publishChannel.map { listOf(it) }
}
wrapper {
gradleVersion = properties("gradleVersion").get()
distributionType = Wrapper.DistributionType.ALL
}
processResources {
filesMatching("**/*.properties") {
filter(EscapeUnicode::class)
}
}
}