ScriptPlugin throws NPE since rc1

The following code works fine with gradle 1.0-milestone-9 and earlier, however it throws a NullPointerException when using rc-1 through rc-3. The problem seems to be the ProfileEventAdapter.buildStarted method was not called before the ProfileEventAdapter.beforeResolve and thus buildProfile has not been initialised.

build.gradle

import org.gradle.GradleLauncher
import org.gradle.api.GradleScriptException
import org.gradle.configuration.ScriptPlugin
import org.gradle.configuration.ScriptPluginFactory
import org.gradle.groovy.scripts.ScriptSource
import org.gradle.groovy.scripts.UriScriptSource
import test.Test
    Test t = new Test()
scriptPluginFactory = GradleLauncher.newInstance().gradle.services.get(ScriptPluginFactory)
ScriptSource source = new UriScriptSource("", new File("test.gradle"))
ScriptPlugin scriptPlugin = scriptPluginFactory.create(source)
scriptPlugin.setClassLoader(this.class.classLoader)
  scriptPlugin.apply(t)
  println t.data

Test.groovy:

package test;
  public class Test {
  String data;
}

test.gradle:

data="22"

You are using a bunch of internal classes here. What exactly are you trying to achieve with this code, instead of, say, ‘apply from: “test.gradle”, to: t’?

We’ve been using this process to set up build meta data objects which describe which sub-projects get compiled into our different products. It’s also used to configure how our installers are built as well as handling several other similar configuration issues.

Unless I’m missing something (please let me know), ‘apply from: “test.gradle”, to: t’ will achieve the same, with less code and without using internal APIs.

Part of the code was running in an IDEA plugin which wouldn’t have direct access to Script interface nor the Project class. However, we’ve decided to refactor those components to take advantage of the apply method. Thanks for your help.