Unit Test with default java security manager

Hi All, I use powermock. I use also advanced feature to mock classes which are declared as ‘final’. In order to make that work I have to set the security manager of the test execution to the default java security manager

test {
            useTestNG()
              doFirst {
                def agent = project.configurations.agent.asPath
                def policy = rootProject.file('osgi/security.policy')
                  // Gradle will execute the tests with a own security manager.
                // This security manager will make PowerMock tests fail
                // Note: -Djava.security.manager <- doesn't work, manager must be specified explicitly.
                jvmArgs.add "-Djava.security.manager=java.lang.SecurityManager"
                jvmArgs.add "-Djava.security.policy=${policy}"
                jvmArgs.add "-javaagent:${agent}"
                jvmArgs.add "-XX:MaxPermSize=512m"
                    ignoreFailures true
            }

In general that works fine but from time to time the tests fail. It seems like that sometimes a test case will be executed with the gradle security manager and sometimes with the the default java security manager.

Any idea why it behaves inconsistent from build to build?