IntelliJ Platform Plugin SDK Help

Recipes

Run a custom task with a customized sandbox location

To create a custom task with the sandbox directory specified outside the default build/idea-sandbox/[TYPE]-[VERSION]/ location, pass the new location to its prepareSandboxTask sandbox producer configuration:

val runWithCustomSandbox by intellijPlatformTesting.runIde.registering { // ... prepareSandboxTask { sandboxDirectory = project.layout.buildDirectory.dir("custom-sandbox") sandboxSuffix = "" } }
intellijPlatformTesting.runIde { runWithCustomSandbox { // ... prepareSandboxTask { sandboxDirectory = project.layout.buildDirectory.dir('custom-sandbox') sandboxSuffix = '' } } }

This will result in the following sandbox structure:

build/ ├── custom-sandbox │   ├── config │   ├── log │   ├── plugins │   └── system ...

Access IntelliJ Platform from any Gradle task

With Task Awares it is possible to enhance any Gradle task with features provided with the IntelliJ Platform Gradle Plugin.

import org.jetbrains.intellij.platform.gradle.tasks.aware.IntelliJPlatformVersionAware abstract class MyTask : DefaultTask(), IntelliJPlatformVersionAware val myTask by tasks.registering(MyTask::class) { doLast { println("platformPath = \n${platformPath}") println("productInfo.buildNumber = ${productInfo.buildNumber}") } }
import org.jetbrains.intellij.platform.gradle.tasks.aware.IntelliJPlatformVersionAware abstract class MyTask extends DefaultTask implements IntelliJPlatformVersionAware {} tasks.register('myTask', MyTask) { doLast { println("platformPath = \n${platformPath}") println("productInfo.buildNumber = ${productInfo.buildNumber}") } }

As soon as the registered task inherits from the *Aware interface, such as IntelliJPlatformVersionAware, all the related information will be injected during the configuration phase.

Bundle additional files with the plugin

Additional files can be bundled by adding them to the plugin directory when preparing the sandbox:

tasks { prepareSandbox { from(layout.projectDirectory.dir("extraFiles")) { into(pluginName.map { "$it/extra" }) } } }
tasks.named('prepareSandbox', PrepareSandboxTask) { from layout.projectDirectory.dir('extraFiles') into it.pluginName.map { "$it/extra" } }

To apply that to the custom task, use the prepareSandboxTask reference:

val runWithCustomSandbox by intellijPlatformTesting.runIde.registering { // ... prepareSandboxTask { from(...) { into(...) } } }
intellijPlatformTesting.runIde { runWithCustomSandbox { // ... prepareSandboxTask { from(...) into(...) } } }

It is possible to apply that to all PrepareSandboxTask with:

tasks { withType<PrepareSandboxTask> { from(...) { into(...) } } }
tasks { withType(PrepareSandboxTask) { from(...) into(...) } }

ProGuard configuration

To configure ProGuard, intercept the prepareSandbox task and replace the plugin Jar archive produced by the composedJar task with the obfuscated/minified file.

First, define the ProGuard Jar archive location and store it inside the build/libs/ directory. Pass the output ProGuard location to the outjars() helper and use it as a new sandbox input for prepareSandbox.pluginJar.

Finally, pass the composedJar.archiveFile to the injars() helper.

import proguard.gradle.ProGuardTask buildscript { repositories { mavenCentral() } dependencies { classpath("com.guardsquare:proguard-gradle:7.5.0") } } tasks { val proguardJar = layout.buildDirectory.file("libs/$name-$version-proguard.jar") val proguard by registering(ProGuardTask::class) { injars(composedJar.map { it.archiveFile }) outjars(proguardJar) // ... } prepareSandbox { pluginJar = proguardJar dependsOn(proguard) } }
import proguard.gradle.ProGuardTask buildscript { repositories { mavenCentral() } dependencies { classpath("com.guardsquare:proguard-gradle:7.5.0") } } def proguardJar = layout.buildDirectory.file("libs/$name-$version-proguard.jar") tasks.register('proguard', ProGuardTask) { it.injars(composedJar.archiveFile) outjars(proguardJar) // ... } prepareSandbox { pluginJar = proguardJar dependsOn(proguard) }
Last modified: 29 August 2024