Skip to content

Commit

Permalink
Migrate to new IntelliJ Platform Gradle Plugin
Browse files Browse the repository at this point in the history
The plugin, formerly known as Gradle IntelliJ Plugin, has been renamed
with version 2. The API has changed significantly.
  • Loading branch information
JojOatXGME committed Jun 14, 2024
1 parent a56ef82 commit c912d4f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 95 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jobs:
- name: Collect metadata for upcoming steps and jobs
id: metadata
run: |
./gradlew --stacktrace metadata listProductsReleases
echo "products-releases=$(jq -Rnc '[inputs]' < build/listProductsReleases.txt)" >> "$GITHUB_OUTPUT"
./gradlew --stacktrace metadata
echo "products-releases=$(./gradlew -q printProductsReleases | jq -Rnc '[inputs]')" >> "$GITHUB_OUTPUT"
# Build
- name: Build project
run: ./gradlew --stacktrace assemble
- name: Package and verify plugin
run: ./gradlew --stacktrace verifyPlugin
run: ./gradlew --stacktrace assemble buildPlugin
- name: Verify plugin
run: ./gradlew --stacktrace verifyPluginStructure
- name: Run linters and tests
run: ./gradlew --stacktrace check
# Upload artifacts
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
key: pluginVerifier-${{ matrix.idea-release }}-${{ runner.os }}
# Run checks
- name: Check plugin compatibility
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" runPluginVerifier
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" verifyPlugin
# Upload artifacts
- name: Upload build reports
if: always()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ hs_err_pid*
**/.gradle
build

/.intellijPlatform
src/gen
145 changes: 82 additions & 63 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.EnumSet

plugins {
id("java")
kotlin("jvm") version embeddedKotlinVersion
alias(libs.plugins.jetbrains.intellij)
alias(libs.plugins.jetbrains.intellij.platform)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.grammarkit)
id("local.bump-version")
Expand Down Expand Up @@ -44,22 +45,94 @@ kotlin {
// Configure project's dependencies
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}

dependencies {
compileOnly(libs.jetbrains.annotations)

testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.jupiter)
testImplementation(libs.junit5.platform.testkit)
testRuntimeOnly(libs.junit5.vintage.engine)

intellijPlatform {
create(platformType, platformVersion)
testFramework(TestFrameworkType.Platform)
instrumentationTools()
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
pluginVerifier("1.307")
}
}

// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij.pluginName = pluginName
intellij {
version = platformVersion
type = platformType
updateSinceUntilBuild = true
// Configure intellij-platform-gradle-plugin plugin.
// Read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
intellijPlatform {
projectName = pluginName
pluginConfiguration {
id = "nix-idea"
name = "NixIDEA"
version = pluginVersion
vendor {
name = "NixOS"
}
ideaVersion {
sinceBuild = pluginSinceBuild
untilBuild = pluginUntilBuild
}
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
description = providers.provider {
projectDir.resolve("README.md").readText().lines()
.run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}
.joinToString("\n")
.run { markdownToHTML(this) }
}
// Get the latest available change notes from the changelog file
changeNotes = provider {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}
verifyPlugin {
ides {
ides(
providers.gradleProperty("verifierIdeVersionOverride")
// Verify only against the IDE specified by the property
.map { listOf(it) }
// If property is not set, verify against the recommended list of IDEs
.orElse(ProductReleasesValueSource())
)
}
failureLevel = EnumSet.complementOf(
EnumSet.of(
FailureLevel.DEPRECATED_API_USAGES,
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
FailureLevel.EXPERIMENTAL_API_USAGES,
)
)
}
publishing {
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}
}

changelog {
Expand Down Expand Up @@ -151,58 +224,4 @@ tasks {
}
}

patchPluginXml {
version = pluginVersion
sinceBuild = pluginSinceBuild
untilBuild = pluginUntilBuild

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription = providers.provider {
projectDir.resolve("README.md").readText().lines()
.run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}
.joinToString("\n")
.run { markdownToHTML(this) }
}

// Get the latest available change notes from the changelog file
changeNotes = provider {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}

runPluginVerifier {
ideVersions = providers.gradleProperty("verifierIdeVersionOverride").map { listOf(it) }.orElse(listOf())
failureLevel = EnumSet.complementOf(
EnumSet.of(
FailureLevel.DEPRECATED_API_USAGES,
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
FailureLevel.EXPERIMENTAL_API_USAGES,
)
)
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
verifierVersion = "1.307"
}

publishPlugin {
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}

}
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# -> https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[libraries]
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
junit5-bom = { module = "org.junit:junit-bom", version = "5.9.1" }
junit5-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit5-platform-testkit = { module = "org.junit.platform:junit-platform-testkit" }
junit5-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine" }

[plugins]
# gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
jetbrains-intellij = { id = "org.jetbrains.intellij", version = "1.17.2" }
# gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
# read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
jetbrains-intellij-platform = { id = "org.jetbrains.intellij.platform", version = "2.0.0-beta7" }
# read more: https://github.com/JetBrains/gradle-changelog-plugin
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.0" }
# grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
# read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
jetbrains-grammarkit = { id = "org.jetbrains.grammarkit", version = "2022.3.2.2" }
3 changes: 2 additions & 1 deletion gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ plugins {
}

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots/")
gradlePluginPortal()
}

dependencies {
implementation(plugin(libs.plugins.jetbrains.intellij))
implementation(plugin(libs.plugins.jetbrains.intellij.platform))
}

/**
Expand Down
26 changes: 9 additions & 17 deletions gradle/plugins/src/main/kotlin/local.jbr-guidance.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.gradle.tooling.Failure
import org.gradle.tooling.events.FailureResult
import org.gradle.tooling.events.FinishEvent
import org.gradle.tooling.events.OperationCompletionListener
import org.jetbrains.intellij.tasks.RunIdeBase
import org.jetbrains.intellij.platform.gradle.tasks.aware.RuntimeAware
import java.util.function.Predicate

val jbrHome = rootProject.file("jbr")
Expand All @@ -15,29 +15,21 @@ task<Exec>("jbr") {
}

jbrHome.resolve("bin/java").takeIf { it.exists() }
?.also { jbrExecutable ->
// Override JVM of gradle-intellij-plugin with JVM at `jbr/bin/java`
// https://github.com/JetBrains/gradle-intellij-plugin/issues/1437#issuecomment-1987310948
tasks.withType<RunIdeBase> {
projectExecutable = jbrExecutable.toString()
}
pluginManager.withPlugin("org.jetbrains.intellij") {
// Uses `withPlugin` because the following code must run after the gradle-intellij-plugin got applied.
// We must also use `afterEvaluate`, as the gradle-intellij-plugin uses `afterEvaluate` as well.
// Otherwise, gradle-intellij-plugin would just overwrite our configuration.
afterEvaluate {
tasks.withType<Test> {
executable = jbrExecutable.toString()
}
?.also { _ ->
// Use JVM at `jbr/bin/java`. The JVM otherwise downloaded by intellij-platform-gradle-plugin wouldn't work on NixOS.
// https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1437#issuecomment-1987310948
tasks.configureEach {
if (this is RuntimeAware) {
runtimeDirectory = jbrHome
}
}
}
?: run {
// There is no JVM at `jbr/bin/java`. Monitor the build and provide some helpful message when it fails.
val service = gradle.sharedServices.registerIfAbsent("jbr-guidance", JbrGuidance::class) {}
serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
// If the configuration cache is enabled, the JBR failure was triggered during serialization
// before any task gets executed. (As of gradle-intellij-plugin 1.17.2 and Gradle 8.6.)
// If the configuration cache is enabled, the JBR failure may be triggered during serialization
// before any task gets executed. (As of intellij-platform-gradle-plugin 2.0.0 and Gradle 8.6.)
// Unfortunately, only failures in tasks are reported to the JbrGuidance build service.
// If there are tasks scheduled, but none of them is executed, we therefore also print the message.
project.gradle.taskGraph.whenReady {
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pluginManagement {
includeBuild("gradle/plugins")
repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots/")
gradlePluginPortal()
}
}

rootProject.name = "NixIDEA"
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<idea-plugin>

<id>nix-idea</id>
<name>NixIDEA</name>
<vendor>NixOS</vendor>

<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends optional="true" config-file="nix-idea-ultimate.xml">com.intellij.modules.ultimate</depends>
Expand Down

0 comments on commit c912d4f

Please sign in to comment.