Isolating forked tests through JVM arguments

Is there a way (we are willing to write a plugin if required) to pass different JVM arguments to each forked test JVM?

Background:
We use https://github.com/JetBrains/gradle-intellij-plugin to build and test an IntelliJ plugin. The issue is that tests have to run serialized in the IntelliJ test frameworks (lots of global state in an IDE…).

We would like to be able to take our X number of tests and fork them off into Y JVMs. Each with different JVM arguments / system properties to isolate the Intellij sandboxes from each other.

We would like to see this done at the Gradle layer so we do not have to worry about tagging tests manually.

Any guidance would be appreciated.

I’d start by poking through the Test task’s source code

Ya, I was doing that.

Thought was extend Test and override createTestExecutionSpec to return a custom JvmTestExecutionSpec that overrides getJavaForkOptions that appends an AtomicInt to the end of the JVM args we need.

The downside is now we are extending internal classes and not sure how safe that is for our long term.