Skip to content

Commit 9700fca

Browse files
authored
Merge pull request #84 from NixOS/intellij-platform-plugin-v2
Intellij Platform Gradle Plugin v2 and IDEA 2024.2
2 parents 852ed2c + b668043 commit 9700fca

File tree

9 files changed

+116
-98
lines changed

9 files changed

+116
-98
lines changed

.github/workflows/build.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ jobs:
4444
- name: Collect metadata for upcoming steps and jobs
4545
id: metadata
4646
run: |
47-
./gradlew --stacktrace metadata listProductsReleases
48-
echo "products-releases=$(jq -Rnc '[inputs]' < build/listProductsReleases.txt)" >> "$GITHUB_OUTPUT"
47+
./gradlew --stacktrace metadata
48+
echo "products-releases=$(./gradlew -q printProductsReleases | jq -Rnc '[inputs]')" >> "$GITHUB_OUTPUT"
4949
# Build
5050
- name: Build project
51-
run: ./gradlew --stacktrace assemble
52-
- name: Package and verify plugin
53-
run: ./gradlew --stacktrace verifyPlugin
51+
run: ./gradlew --stacktrace assemble buildPlugin
52+
- name: Verify plugin
53+
run: ./gradlew --stacktrace verifyPluginStructure
5454
- name: Run linters and tests
5555
run: ./gradlew --stacktrace check
5656
# Upload artifacts
@@ -99,7 +99,7 @@ jobs:
9999
key: pluginVerifier-${{ matrix.idea-release }}-${{ runner.os }}
100100
# Run checks
101101
- name: Check plugin compatibility
102-
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" runPluginVerifier
102+
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" verifyPlugin
103103
# Upload artifacts
104104
- name: Upload build reports
105105
if: always()

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ out/
2626
build/
2727
!src/**/build/
2828

29+
/.intellijPlatform
2930
src/gen

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
### Added
66

7+
- Support for IDEA 2024.2
8+
79
### Changed
810

911
### Deprecated
1012

1113
### Removed
1214

15+
- Support for IDEA 2023.2
16+
1317
### Fixed
1418

1519
### Security

build.gradle.kts

+84-63
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import org.jetbrains.changelog.Changelog
22
import org.jetbrains.changelog.markdownToHTML
3-
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
3+
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
4+
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel
45
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
56
import java.util.EnumSet
67

78
plugins {
89
id("java")
910
kotlin("jvm") version embeddedKotlinVersion
10-
alias(libs.plugins.jetbrains.intellij)
11+
alias(libs.plugins.jetbrains.intellij.platform)
1112
alias(libs.plugins.jetbrains.changelog)
1213
alias(libs.plugins.jetbrains.grammarkit)
1314
id("local.bump-version")
@@ -44,22 +45,96 @@ kotlin {
4445
// Configure project's dependencies
4546
repositories {
4647
mavenCentral()
48+
intellijPlatform {
49+
defaultRepositories()
50+
}
4751
}
4852

4953
dependencies {
54+
compileOnly(libs.jetbrains.annotations)
55+
5056
testImplementation(platform(libs.junit5.bom))
5157
testImplementation(libs.junit5.jupiter)
5258
testImplementation(libs.junit5.platform.testkit)
59+
testImplementation(libs.junit4)
5360
testRuntimeOnly(libs.junit5.vintage.engine)
61+
62+
intellijPlatform {
63+
create(platformType, platformVersion)
64+
testFramework(TestFrameworkType.Platform)
65+
//testFramework(TestFrameworkType.JUnit5)
66+
instrumentationTools()
67+
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
68+
// https://youtrack.jetbrains.com/issue/MP-6388
69+
pluginVerifier("1.307")
70+
}
5471
}
5572

56-
// Configure gradle-intellij-plugin plugin.
57-
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
58-
intellij.pluginName = pluginName
59-
intellij {
60-
version = platformVersion
61-
type = platformType
62-
updateSinceUntilBuild = true
73+
// Configure intellij-platform-gradle-plugin plugin.
74+
// Read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
75+
intellijPlatform {
76+
projectName = pluginName
77+
pluginConfiguration {
78+
id = "nix-idea"
79+
name = "NixIDEA"
80+
version = pluginVersion
81+
vendor {
82+
name = "NixOS"
83+
}
84+
ideaVersion {
85+
sinceBuild = pluginSinceBuild
86+
untilBuild = pluginUntilBuild
87+
}
88+
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
89+
description = providers.provider {
90+
projectDir.resolve("README.md").readText().lines()
91+
.run {
92+
val start = "<!-- Plugin description -->"
93+
val end = "<!-- Plugin description end -->"
94+
if (!containsAll(listOf(start, end))) {
95+
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
96+
}
97+
subList(indexOf(start) + 1, indexOf(end))
98+
}
99+
.joinToString("\n")
100+
.run { markdownToHTML(this) }
101+
}
102+
// Get the latest available change notes from the changelog file
103+
changeNotes = provider {
104+
with(changelog) {
105+
renderItem(
106+
(getOrNull(pluginVersion) ?: getUnreleased())
107+
.withHeader(false)
108+
.withEmptySections(false),
109+
Changelog.OutputType.HTML
110+
)
111+
}
112+
}
113+
}
114+
verifyPlugin {
115+
ides {
116+
ides(
117+
providers.gradleProperty("verifierIdeVersionOverride")
118+
// Verify only against the IDE specified by the property
119+
.map { listOf(it) }
120+
// If property is not set, verify against the recommended list of IDEs
121+
.orElse(ProductReleasesValueSource())
122+
)
123+
}
124+
failureLevel = EnumSet.complementOf(
125+
EnumSet.of(
126+
FailureLevel.DEPRECATED_API_USAGES,
127+
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
128+
FailureLevel.EXPERIMENTAL_API_USAGES,
129+
)
130+
)
131+
}
132+
publishing {
133+
token = providers.environmentVariable("JETBRAINS_TOKEN")
134+
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
135+
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
136+
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
137+
}
63138
}
64139

65140
changelog {
@@ -151,58 +226,4 @@ tasks {
151226
}
152227
}
153228

154-
patchPluginXml {
155-
version = pluginVersion
156-
sinceBuild = pluginSinceBuild
157-
untilBuild = pluginUntilBuild
158-
159-
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
160-
pluginDescription = providers.provider {
161-
projectDir.resolve("README.md").readText().lines()
162-
.run {
163-
val start = "<!-- Plugin description -->"
164-
val end = "<!-- Plugin description end -->"
165-
if (!containsAll(listOf(start, end))) {
166-
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
167-
}
168-
subList(indexOf(start) + 1, indexOf(end))
169-
}
170-
.joinToString("\n")
171-
.run { markdownToHTML(this) }
172-
}
173-
174-
// Get the latest available change notes from the changelog file
175-
changeNotes = provider {
176-
with(changelog) {
177-
renderItem(
178-
(getOrNull(pluginVersion) ?: getUnreleased())
179-
.withHeader(false)
180-
.withEmptySections(false),
181-
Changelog.OutputType.HTML
182-
)
183-
}
184-
}
185-
}
186-
187-
runPluginVerifier {
188-
ideVersions = providers.gradleProperty("verifierIdeVersionOverride").map { listOf(it) }.orElse(listOf())
189-
failureLevel = EnumSet.complementOf(
190-
EnumSet.of(
191-
FailureLevel.DEPRECATED_API_USAGES,
192-
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
193-
FailureLevel.EXPERIMENTAL_API_USAGES,
194-
)
195-
)
196-
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
197-
// https://youtrack.jetbrains.com/issue/MP-6388
198-
verifierVersion = "1.307"
199-
}
200-
201-
publishPlugin {
202-
token = providers.environmentVariable("JETBRAINS_TOKEN")
203-
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
204-
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
205-
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
206-
}
207-
208229
}

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
pluginGroup = org.nixos.idea
55
pluginName = NixIDEA
66
pluginVersion = 0.4.0.15
7-
pluginSinceBuild = 232
8-
pluginUntilBuild = 241.*
7+
pluginSinceBuild = 233
8+
pluginUntilBuild = 242.*
99

1010
platformType = IU
11-
platformVersion = 2023.2.6
11+
platformVersion = 2023.3.7
1212

1313
# Gradle Configuration
1414
# -> https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

gradle/libs.versions.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
# -> https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
33

44
[libraries]
5+
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
56
junit5-bom = { module = "org.junit:junit-bom", version = "5.9.1" }
67
junit5-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
78
junit5-platform-testkit = { module = "org.junit.platform:junit-platform-testkit" }
89
junit5-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine" }
10+
junit4 = { module = "junit:junit", version = "4.13.2" }
911

1012
[plugins]
11-
# gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
12-
jetbrains-intellij = { id = "org.jetbrains.intellij", version = "1.17.2" }
13-
# gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
13+
# read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
14+
jetbrains-intellij-platform = { id = "org.jetbrains.intellij.platform", version = "2.0.1" }
15+
# read more: https://github.com/JetBrains/gradle-changelog-plugin
1416
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.0" }
15-
# grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
17+
# read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
1618
jetbrains-grammarkit = { id = "org.jetbrains.grammarkit", version = "2022.3.2.2" }

gradle/plugins/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repositories {
77
}
88

99
dependencies {
10-
implementation(plugin(libs.plugins.jetbrains.intellij))
10+
implementation(plugin(libs.plugins.jetbrains.intellij.platform))
1111
}
1212

1313
/**

gradle/plugins/src/main/kotlin/local.jbr-guidance.gradle.kts

+11-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import org.gradle.tooling.Failure
33
import org.gradle.tooling.events.FailureResult
44
import org.gradle.tooling.events.FinishEvent
55
import org.gradle.tooling.events.OperationCompletionListener
6-
import org.jetbrains.intellij.tasks.RunIdeBase
6+
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
7+
import org.jetbrains.intellij.platform.gradle.tasks.aware.RuntimeAware
78
import java.util.function.Predicate
89

910
val jbrHome = rootProject.file("jbr")
@@ -15,29 +16,22 @@ task<Exec>("jbr") {
1516
}
1617

1718
jbrHome.resolve("bin/java").takeIf { it.exists() }
18-
?.also { jbrExecutable ->
19-
// Override JVM of gradle-intellij-plugin with JVM at `jbr/bin/java`
20-
// https://github.com/JetBrains/gradle-intellij-plugin/issues/1437#issuecomment-1987310948
21-
tasks.withType<RunIdeBase> {
22-
projectExecutable = jbrExecutable.toString()
23-
}
24-
pluginManager.withPlugin("org.jetbrains.intellij") {
25-
// Uses `withPlugin` because the following code must run after the gradle-intellij-plugin got applied.
26-
// We must also use `afterEvaluate`, as the gradle-intellij-plugin uses `afterEvaluate` as well.
27-
// Otherwise, gradle-intellij-plugin would just overwrite our configuration.
28-
afterEvaluate {
29-
tasks.withType<Test> {
30-
executable = jbrExecutable.toString()
31-
}
19+
?.also { _ ->
20+
// Use JVM at `jbr/bin/java`. The JVM otherwise downloaded by intellij-platform-gradle-plugin wouldn't work on NixOS.
21+
// https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1437#issuecomment-1987310948
22+
// VerifyPluginTask doesn't execute the JVM, so we can ignore this task for the sake of consistency with other platforms.
23+
tasks.configureEach {
24+
if (this is RuntimeAware && this !is VerifyPluginTask) {
25+
runtimeDirectory = jbrHome
3226
}
3327
}
3428
}
3529
?: run {
3630
// There is no JVM at `jbr/bin/java`. Monitor the build and provide some helpful message when it fails.
3731
val service = gradle.sharedServices.registerIfAbsent("jbr-guidance", JbrGuidance::class) {}
3832
serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
39-
// If the configuration cache is enabled, the JBR failure was triggered during serialization
40-
// before any task gets executed. (As of gradle-intellij-plugin 1.17.2 and Gradle 8.6.)
33+
// If the configuration cache is enabled, the JBR failure may be triggered during serialization
34+
// before any task gets executed. (As of intellij-platform-gradle-plugin 2.0.0 and Gradle 8.6.)
4135
// Unfortunately, only failures in tasks are reported to the JbrGuidance build service.
4236
// If there are tasks scheduled, but none of them is executed, we therefore also print the message.
4337
project.gradle.taskGraph.whenReady {

src/main/resources/META-INF/plugin.xml

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<idea-plugin>
22

3-
<id>nix-idea</id>
4-
<name>NixIDEA</name>
5-
<vendor>NixOS</vendor>
6-
73
<depends>com.intellij.modules.platform</depends>
84
<depends>com.intellij.modules.lang</depends>
95
<depends optional="true" config-file="nix-idea-ultimate.xml">com.intellij.modules.ultimate</depends>

0 commit comments

Comments
 (0)