ScriptPlugin throws NPE since rc1

(thoward) #1

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.


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()
ScriptSource source = new UriScriptSource("", new File("test.gradle"))
ScriptPlugin scriptPlugin = scriptPluginFactory.create(source)


package test;
  public class Test {
  String data;



(Peter Niederwieser) #2

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’?

(thoward) #3

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.

(Peter Niederwieser) #4

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.

(thoward) #5

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.