Recipes
To create a custom task with the sandbox directory specified outside the default buildprepareSandboxTask
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
...
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.
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(...)
}
}
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 buildoutjars()
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)
}
When running the IDE from the command line, you can pass an argument, like a path to the project or file, to open it automatically. This is also possible when using the runIde
task:
tasks {
runIde {
argumentProviders += CommandLineArgumentProvider {
listOf("/path/to/the/project")
}
}
}
runIde {
argumentProviders.add({
['/path/to/the/project']
} as CommandLineArgumentProvider)
}