Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3044

preserve classLoader in Script.evaluate() method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.4
    • 1.6.5, 1.7-beta-2
    • None
    • None

    Description

      I'm using the ant task to run a groovy script. It first does some preparation stuff so users of the system can rely on it in their scripts. The way it reads is something like:

      do_some_stuff_and_set_some_vars;
      evaluate(myScript);

      When I set additional classpath through the ant task and have "import package.from.the.additional.classpath.class", it is available in the step "do_some_stuff_and_set_some_vars", but it is not available in the evaluate step. Fails with "unable to resolve class package.from.the.additional.classpath.class".

      To workaround I do
      gsh = new GroovyShell(this.class.classLoader, getBinding());
      gsh.evaluate(myScript);

      And now works. So I believe this is a bug because one would expect to have the same parent ClassLoader besides Binding when using the Script.evaluate() method.

      When using the command line groovy this is not really an issue because classpath is set globally through the -cp argument. But when running groovy scripts programatically like with ant, then it turns out to be an issue.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            avalon A
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: