From 3dab4e1787dee0e4ddb9c5336c781ec1652cd412 Mon Sep 17 00:00:00 2001 From: Peddi Ashrith Kumar Date: Fri, 20 Sep 2024 05:43:09 +0530 Subject: [PATCH] Upgrade to Intellij platform gradle plugin 2.0 (#70) Co-authored-by: Ashrith Kumar Peddi --- .github/workflows/build.yml | 2 +- .github/workflows/pr.yml | 2 +- .github/workflows/release.yml | 2 +- .gitignore | 1 + build.gradle.kts | 155 ++++++++++-------- .../main/kotlin/plugin/PluginDescriptor.kt | 10 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 100 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36e192f..bb171cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - product: [ "IC-2022.2", "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1"] + product: [ "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1" ] max-parallel: 5 env: PRODUCT_NAME: ${{ matrix.product }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8094d53..901d109 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - product: [ "IC-2022.2", "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1" ] + product: [ "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1" ] max-parallel: 5 env: PRODUCT_NAME: ${{ matrix.product }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ea5f08f..ff67a22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: release: strategy: matrix: - product: [ "IC-2022.2", "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1" ] + product: [ "IC-2023.1", "IC-2023.2", "IC-2023.3", "IC-2024.1" ] max-parallel: 1 env: PRODUCT_NAME: ${{ matrix.product }} diff --git a/.gitignore b/.gitignore index efa321e..38cd228 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build *.iml *.ipr *.iws +.intellijPlatform diff --git a/build.gradle.kts b/build.gradle.kts index a02cf98..0dede27 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,10 @@ +import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType +import org.jetbrains.intellij.platform.gradle.models.ProductRelease +import org.jetbrains.intellij.platform.gradle.TestFrameworkType import plugin.PluginDescriptor import plugin.PluginDescriptor.KotlinOptions import plugin.PlatformType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet buildscript { repositories { @@ -10,77 +12,76 @@ buildscript { } } +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + plugins { kotlin("jvm") - id("org.jetbrains.intellij") version "1.15.0" + id("org.jetbrains.intellij.platform") version "2.0.1" } repositories { mavenCentral() + + intellijPlatform { + defaultRepositories() + } } val plugins = listOf( - PluginDescriptor( - since = "222", - until = "223.*", - sdkVersion = "IC-2022.2", - platformType = PlatformType.IdeaCommunity, - sourceFolder = "IC-222", - kotlin = KotlinOptions( - apiVersion = "1.6" - ), - dependencies = listOf("java", "Kotlin") - ), PluginDescriptor( since = "231", until = "231.*", - sdkVersion = "IC-2023.1", + platformVersion = "2023.1", platformType = PlatformType.IdeaCommunity, sourceFolder = "IC-231", kotlin = KotlinOptions( apiVersion = "1.6" ), - dependencies = listOf("java", "Kotlin") + bundledDependencies = listOf("com.intellij.java", "org.jetbrains.kotlin") ), PluginDescriptor( since = "232", until = "232.*", - sdkVersion = "IC-2023.2", + platformVersion = "2023.2", platformType = PlatformType.IdeaCommunity, sourceFolder = "IC-232", kotlin = KotlinOptions( apiVersion = "1.6" ), - dependencies = listOf("java", "Kotlin") + bundledDependencies = listOf("com.intellij.java", "org.jetbrains.kotlin") ), PluginDescriptor( since = "233", until = "233.*", - sdkVersion = "IC-2023.3", + platformVersion = "2023.3", platformType = PlatformType.IdeaCommunity, sourceFolder = "IC-233", kotlin = KotlinOptions( apiVersion = "1.6" ), - dependencies = listOf("java", "Kotlin") + bundledDependencies = listOf("com.intellij.java", "org.jetbrains.kotlin") ), PluginDescriptor( - since = "241", - until = "241.*", - sdkVersion = "IC-2024.1", - platformType = PlatformType.IdeaCommunity, - sourceFolder = "IC-241", - kotlin = KotlinOptions( - apiVersion = "1.6" - ), - dependencies = listOf("java", "Kotlin") + since = "241", + until = "241.*", + platformVersion = "2024.1", + platformType = PlatformType.IdeaCommunity, + sourceFolder = "IC-241", + kotlin = KotlinOptions( + apiVersion = "1.6" + ), + bundledDependencies = listOf("com.intellij.java", "org.jetbrains.kotlin") ) ) -val defaultProductName = "IC-2024.1" +val defaultProductName = "IC-2023.1" val productName = System.getenv("PRODUCT_NAME") ?: defaultProductName val maybeGithubRunNumber = System.getenv("GITHUB_RUN_NUMBER")?.toInt() -val descriptor = plugins.first { it.sdkVersion == productName } +val descriptor = plugins.first { it.getSDKVersion() == productName } // Import variables from gradle.properties file val pluginGroup: String by project @@ -88,7 +89,7 @@ val pluginGroup: String by project // `pluginName_` variable ends with `_` because of the collision with Kotlin magic getter in the `intellij` closure. // Read more about the issue: https://github.com/JetBrains/intellij-platform-plugin-template/issues/29 val pluginName_: String by project -val pluginVersion: String = pluginVersion(major = "2", minor = "6", patch = "1") +val pluginVersion: String = pluginVersion(major = "2", minor = "7", patch = "1") val pluginDescriptionFile: String by project val pluginChangeNotesFile: String by project @@ -98,28 +99,63 @@ val packageVersion: String by project group = pluginGroup version = packageVersion -logger.lifecycle("Building Amazon Ion $pluginVersion for ${descriptor.platformType} ${descriptor.sdkVersion}") +logger.lifecycle("Building Amazon Ion $pluginVersion for ${descriptor.platformType} ${descriptor.platformVersion}") dependencies { - // Kotlin runtime dependency is provided by the IntelliJ platform. + intellijPlatform { + create(descriptor.platformType.acronym, descriptor.platformVersion) // https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html#setting-up-intellij-platform + bundledPlugins(descriptor.bundledDependencies) + pluginVerifier() + instrumentationTools() + + testFramework(TestFrameworkType.Platform) + } + + testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") + testCompileOnly("junit:junit:4.13") + testRuntimeOnly("org.junit.vintage:junit-vintage-engine") } -intellij { - pluginName.set(pluginName_) - version.set(descriptor.sdkVersion) - type.set(descriptor.platformType.acronym) - downloadSources.set(true) - updateSinceUntilBuild.set(false) +intellijPlatform { + pluginConfiguration { + name.set(pluginName_) + version.set(descriptor.platformVersion) + description.set(readResource(pluginDescriptionFile)) + changeNotes.set(readResource(pluginChangeNotesFile)) + + ideaVersion { + sinceBuild.set(descriptor.since) + untilBuild.set(descriptor.until) + } + } + + publishing { + token.set(System.getenv("PUBLISH_TOKEN")) + + // Publish to beta unless release is specified. + if (System.getenv("PUBLISH_CHANNEL") != "release") { + channels.set(listOf("beta")) + } + } - // Plugin Dependencies -> https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html - // Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 - plugins.set(descriptor.dependencies) + pluginVerification { + ides { + ide(IntelliJPlatformType.IntellijIdeaCommunity, descriptor.platformVersion) + recommended() + select { + types.set(listOf(IntelliJPlatformType.IntellijIdeaCommunity)) + channels.set(listOf(ProductRelease.Channel.BETA)) + sinceBuild.set(descriptor.since) + untilBuild.set(descriptor.until) + } + } + } } sourceSets { main { - withConvention(KotlinSourceSet::class) { - kotlin.srcDir("src/${descriptor.sourceFolder}/kotlin") + kotlin { + srcDir("src/${descriptor.sourceFolder}/kotlin") } resources { @@ -155,25 +191,7 @@ tasks { } buildPlugin { - archiveClassifier.set(descriptor.sdkVersion) - } - - patchPluginXml { - version.set(pluginVersion) - sinceBuild.set(descriptor.since) - untilBuild.set(descriptor.until) - - pluginDescription.set(readResource(pluginDescriptionFile)) - changeNotes.set(readResource(pluginChangeNotesFile)) - } - - publishPlugin { - token.set(System.getenv("PUBLISH_TOKEN")) - - // Publish to beta unless release is specified. - if (System.getenv("PUBLISH_CHANNEL") != "release") { - channels.set(listOf("beta")) - } + archiveClassifier.set(descriptor.getSDKVersion()) } } @@ -192,10 +210,11 @@ fun readResource(name: String) = file("resources/$name").readText() * major: 2 * minor: 1 * patch: 1 - * sdkVersion: IC-2022.2 + * platformVersion: 2024.2 + * platformType: IC * * RETURNS: - * 2.1.1+30-IC-2022.2 + * 2.1.1+30-IC-2024.2 * * * GIVEN (local dev environment): @@ -203,7 +222,8 @@ fun readResource(name: String) = file("resources/$name").readText() * major: 2 * minor: 2 * patch: 34 - * sdkVersion: IC-2022.3 + * platformVersion: 2022.3 + * platformType: IC * * RETURNS: * 2.2.34+0-IC-2022.3+alpha @@ -212,5 +232,6 @@ fun pluginVersion(major: String, minor: String, patch: String) = listOf( major, minor, - maybeGithubRunNumber?.let { "$patch+$it-${descriptor.sdkVersion}" } ?: "$patch+0-${descriptor.sdkVersion}+alpha" + maybeGithubRunNumber?.let { "$patch+$it-${descriptor.getSDKVersion()}" } + ?: "$patch+0-${descriptor.getSDKVersion()}+alpha" ).joinToString(".") diff --git a/buildSrc/src/main/kotlin/plugin/PluginDescriptor.kt b/buildSrc/src/main/kotlin/plugin/PluginDescriptor.kt index b1fb21f..e4919e3 100644 --- a/buildSrc/src/main/kotlin/plugin/PluginDescriptor.kt +++ b/buildSrc/src/main/kotlin/plugin/PluginDescriptor.kt @@ -23,9 +23,9 @@ data class PluginDescriptor( val platformType: PlatformType, /** - * The Platform SDK Version that this distribution will run on. + * The Platform Version that this distribution will run on. */ - val sdkVersion: String, + val platformVersion: String, /** * Source folder which defines source code specific to this distribution. @@ -40,7 +40,7 @@ data class PluginDescriptor( /** * Plugin dependencies. {@see https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html} */ - val dependencies: List + val bundledDependencies: List ) { data class KotlinOptions( /** @@ -49,6 +49,10 @@ data class PluginDescriptor( */ val apiVersion: String ) + + fun getSDKVersion(): String { + return platformType.acronym + "-" + platformVersion + } } enum class PlatformType(val acronym: String) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 98debb8..d642e7f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists