plugin-under-test-metadata.properties not created by Gradle TestKit when running tests in IDEA
After determining the problem was in IDEA only, I've found https://plugins.gradle.org/plugin/com.palantir.idea-test-fix and added
plugins {
id "com.palantir.idea-test-fix" version "0.1.0"
}
to the beginning of build.gradle
for the plugin subproject. It fixes the problem.
In this post (Russian), I found another solution: in Settings-> Build-> Build Tools->Gradle->Runner
, select Gradle Test Runner
instead of Platform Test Runner
, then delete the test's run/debug configuration before running it again.
plugins {
id "org.jetbrains.gradle.plugin.idea-ext" version "0.4.2"
}
task fixIdeaPluginClasspath {
doFirst {
configure(tasks.pluginUnderTestMetadata) {
def ideaClassesPath = project.buildDir.toPath().resolveSibling("out").resolve("production")
def newClasspath = pluginClasspath as List
newClasspath.add(0, ideaClassesPath)
pluginClasspath.setFrom(newClasspath)
}
}
}
pluginUnderTestMetadata.mustRunAfter(fixIdeaPluginClasspath)
idea.project.settings {
taskTriggers {
beforeBuild fixIdeaPluginClasspath, pluginUnderTestMetadata
}
}
This works with IDEA 2019.1 (and may very well work with earlier versions as well).
This utilizes JetBrains' own gradle plugin for configuring IDEA settings to execute both pluginUnderTestMetadata
and the custom fixIdeaPluginClasspath
before each build (the latter will only run from within the IDEA, not when running native gradle).
The first task -- pluginUnderTestMetadata
-- makes sure to create the properties file, and is executed by native Gradle as well.
The second task -- fixIdeaPluginClasspath
-- fixes another bug with how IDEA executes tests: The classpath generated by pluginUnderTestMetadata
will only contain reference to the "$projectDir/build"
directory, which is not where IDEA outputs its compiled classes; hence, you will not see changes you've made in the plugin code that were compiled by IDEA, but only those compiled by native gradle. What it does then is to prepend the IDEA classes directory to the classpath. At first I also tried removing the "$projectDir/build"
reference(s), but gradle then didn't like it complaining about plugin namespace problems (too voodoo for me).
Thanks to @krzychu for pointing out pluginUnderTestMetadata
(on an earlier answer's comment).
In Gradle 4, I was trying to use gradleTestKit()
and got this error.
- adding the below plugin fixed it.
plugins {
id 'java-gradle-plugin'
}