|
| 1 | +// Copyright (c) 2024 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License.AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +import io.gitlab.arturbosch.detekt.Detekt |
| 6 | +import org.jetbrains.changelog.Changelog |
| 7 | +import org.jetbrains.changelog.markdownToHTML |
| 8 | +import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType |
| 9 | +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 10 | + |
| 11 | +fun properties(key: String) = project.findProperty(key).toString() |
| 12 | + |
| 13 | +plugins { |
| 14 | + // Java support |
| 15 | + id("java") |
| 16 | + // Kotlin support - check the latest version at https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm |
| 17 | + id("org.jetbrains.kotlin.jvm") version "2.0.0" |
| 18 | + // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin |
| 19 | + id("org.jetbrains.intellij.platform") version "2.0.0" |
| 20 | +// id("org.jetbrains.intellij.platform.migration") version "2.0.0-beta8" |
| 21 | + // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin |
| 22 | + id("org.jetbrains.changelog") version "1.1.2" |
| 23 | + // detekt linter - read more: https://detekt.github.io/detekt/gradle.html |
| 24 | + id("io.gitlab.arturbosch.detekt") version "1.23.6" |
| 25 | + // ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle |
| 26 | + id("org.jlleitschuh.gradle.ktlint") version "10.0.0" |
| 27 | + // Gradle Properties Plugin - read more: https://github.com/stevesaliman/gradle-properties-plugin |
| 28 | + id("net.saliman.properties") version "1.5.2" |
| 29 | +} |
| 30 | + |
| 31 | +group = properties("pluginGroup") |
| 32 | +val environmentName = properties("environmentName") |
| 33 | +var pluginVersion = properties("pluginVersion") |
| 34 | + |
| 35 | +if (environmentName.isNotBlank()) { |
| 36 | + pluginVersion += "-$environmentName" |
| 37 | +} |
| 38 | + |
| 39 | +project(":") { |
| 40 | + kotlin { |
| 41 | + val excludedPackage = if (environmentName == "latest") "stable" else "latest" |
| 42 | + sourceSets["main"].kotlin.exclude("io/gitpod/jetbrains/gateway/${excludedPackage}/**") |
| 43 | + } |
| 44 | + |
| 45 | + sourceSets { |
| 46 | + main { |
| 47 | + resources.srcDirs("src/main/resources-${environmentName}") |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +repositories { |
| 53 | + mavenCentral() |
| 54 | + intellijPlatform { |
| 55 | + defaultRepositories() |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +dependencies { |
| 60 | + implementation(project(":gitpod-protocol")) { |
| 61 | + artifact { |
| 62 | + type = "jar" |
| 63 | + } |
| 64 | + } |
| 65 | + compileOnly("javax.websocket:javax.websocket-api:1.1") |
| 66 | + compileOnly("org.eclipse.jetty.websocket:websocket-api:9.4.44.v20210927") |
| 67 | + testImplementation(kotlin("test")) |
| 68 | + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.18.1") |
| 69 | + // https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/javax-websocket-client-impl |
| 70 | + implementation("org.eclipse.jetty.websocket:javax-websocket-client-impl:9.4.44.v20210927") |
| 71 | +} |
| 72 | + |
| 73 | +dependencies { |
| 74 | + intellijPlatform { |
| 75 | + // https://www.jetbrains.com/updates/updates.xml |
| 76 | + create(IntelliJPlatformType.Gateway, properties("platformVersion")) |
| 77 | +// create(IntelliJPlatformType.Gateway) |
| 78 | + bundledPlugins(properties("platformBundledPlugins").split(',').map{ it.trim() }) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// Configure gradle-intellij-plugin plugin. |
| 83 | +intellijPlatform { |
| 84 | + pluginConfiguration { |
| 85 | + name = properties("pluginName") |
| 86 | + version = pluginVersion |
| 87 | + |
| 88 | + description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map { |
| 89 | + val start = "<!-- Plugin description -->" |
| 90 | + val end = "<!-- Plugin description end -->" |
| 91 | + |
| 92 | + with(it.lines()) { |
| 93 | + if (!containsAll(listOf(start, end))) { |
| 94 | + throw GradleException("Plugin description section not found in README.md:\n$start ... $end") |
| 95 | + } |
| 96 | + subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML) |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + changeNotes = changelog.getLatest().toHTML() |
| 101 | + |
| 102 | + ideaVersion { |
| 103 | + sinceBuild = properties("pluginSinceBuild") |
| 104 | + untilBuild = properties("pluginUntilBuild") |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + verifyPlugin { |
| 109 | + ides { |
| 110 | + properties("pluginVerifierIdeVersions").split(',').map(String::trim).forEach { version -> |
| 111 | + ide(IntelliJPlatformType.Gateway, version) |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + publishing { |
| 117 | + token = providers.environmentVariable("JB_MARKETPLACE_PUBLISH_TOKEN").getOrElse("") |
| 118 | + var pluginChannels = providers.environmentVariable("JB_GATEWAY_GITPOD_PLUGIN_CHANNEL").getOrElse("Dev") |
| 119 | + if (pluginChannels.contains("-main-gha.")) { |
| 120 | + pluginChannels = "Stable" |
| 121 | + } |
| 122 | + channels = listOf(pluginChannels) |
| 123 | + } |
| 124 | + instrumentCode = false |
| 125 | +} |
| 126 | + |
| 127 | +changelog { |
| 128 | + version = pluginVersion |
| 129 | + groups = emptyList() |
| 130 | +} |
| 131 | + |
| 132 | +// Configure detekt plugin. |
| 133 | +// Read more: https://detekt.github.io/detekt/kotlindsl.html |
| 134 | +detekt { |
| 135 | + autoCorrect = true |
| 136 | + buildUponDefaultConfig = true |
| 137 | +} |
| 138 | + |
| 139 | +tasks.withType<Detekt> { |
| 140 | + jvmTarget = "21" |
| 141 | +} |
| 142 | + |
| 143 | +tasks.withType<KotlinCompile> { |
| 144 | + kotlinOptions.jvmTarget = "21" |
| 145 | +} |
| 146 | + |
| 147 | +tasks.withType<JavaCompile> { |
| 148 | + sourceCompatibility = "21" |
| 149 | + targetCompatibility = "21" |
| 150 | +} |
| 151 | + |
| 152 | +tasks { |
| 153 | + |
| 154 | + buildSearchableOptions { |
| 155 | + enabled = false |
| 156 | + } |
| 157 | + |
| 158 | + test { |
| 159 | + useJUnitPlatform() |
| 160 | + } |
| 161 | + |
| 162 | + register("buildFromLeeway") { |
| 163 | + if ("true" == System.getenv("DO_PUBLISH")) { |
| 164 | + print("publishing $pluginVersion...") |
| 165 | + dependsOn("publishPlugin") |
| 166 | + } else { |
| 167 | + print("building $pluginVersion...") |
| 168 | + dependsOn("buildPlugin") |
| 169 | + } |
| 170 | + } |
| 171 | +} |
0 commit comments