# Is it possible to compile groovy script task statically

**URL:** <https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300>\
**Category:** Flowable Engine\
**Created:** [February 15, 2017, 4:40pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300 "2017-02-15T16:40:41Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tvh](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@tvh](https://forum.flowable.org/u/tvh)\
**Post date:** [February 15, 2017, 4:40pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/1 "2017-02-15T16:40:41Z")

</div>

Is it possible to get script tasks of a process to be statically compiled?

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [February 16, 2017, 7:51am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/2 "2017-02-16T07:51:56Z")

</div>

The Groovy scripting engine is used to evaluate the script. If there are options to use statically compile scripts in the Groovy scripting engine then we could have a look at how to support it. Right now, it’s evaluated at execution time.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [February 20, 2017, 9:17pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/3 "2017-02-20T21:17:08Z")

</div>

I performed some tests and results are encouraging. Some AST transformations must be added so probably best way to implement it is to create new class which extends org.codehaus.groovy.jsr223.GroovyScriptEngineImpl similarly to JuelScriptEngine.  
Let me know if you want me to implement it or you prefer to do it by yourself, I can provide some more hints as well as code.

Best regards,  
Filip

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [February 21, 2017, 10:05am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/4 "2017-02-21T10:05:46Z")

</div>

Hi Filip,

Great, if you could help with a contribution here that would be preferable (mainly because there’s not much Groovy knowledge in the core Flowable team). Let us know if we can help.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [February 21, 2017, 11:29pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/5 "2017-02-21T23:29:03Z")

</div>

Hi Tijs.  
I’m glad I can contribute to a such great project . Should I create issue or pull request is enough?

Best regards  
Filip

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [February 22, 2017, 7:36am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/6 "2017-02-22T07:36:28Z")

</div>

Hi Filip,

It’s great that have you as a contributor to the Flowable project.  
A pull request should be enough.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![PHH](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/phh/32/94_2.png) [@PHH](https://forum.flowable.org/u/PHH)\
**Post date:** [February 22, 2017, 8:37am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/7 "2017-02-22T08:37:29Z")

</div>

Nice one, Filip - many thanks for your contribution!

Cheers  
Paul.

---

<div class="post-metadata">

**Author:** ![ilgrosso](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ilgrosso/32/116_2.png) [@ilgrosso](https://forum.flowable.org/u/ilgrosso)\
**Post date:** [February 22, 2017, 9:30am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/8 "2017-02-22T09:30:50Z")

</div>

Could you please point out the actual modification? (PR is just fine)  
Thanks!

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [March 3, 2017, 1:39pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/9 "2017-03-03T13:39:01Z")

</div>

Hi.  
I made the first version of the static compilation. It works but in my opinion this solution has too many limitations to enable it in the project. Firstly, from now groovy-all must be on the path because some classes from groovy package are used in scripting engine. In addition, the process variables are not visible inscript (type is unknown at compile time). Values from script is not assigned to the process variables (for the same reason). The result can be picked up only as `flowable: resultVariable`.  
The code can be found here (branch StaticallyGroovyScriptsCompilation):  
[https://github.com/fgroch/flowable-engine/tree/StaticallyGroovyScriptsCompilation](https://github.com/fgroch/flowable-engine/tree/StaticallyGroovyScriptsCompilation)  
I added `testStaticallyScriptCompilation` to `GroovyScriptTest` class where you can check it out.  
The advantage of my work on this is that I know flowable better for now and I could efficiently contribute 🙂.  
I am waiting for your opinions.

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [March 4, 2017, 8:46am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/10 "2017-03-04T08:46:24Z")

</div>

Hi,

Thanks, I think the changes you made are good.  
The statically compile version of the Groovy script engine should be separated in a new Flowable module to prevent the engine from having the groovy-all dependency as requirement. Or we should use reflection to load the statically compile Groovy engine instead. We do something similar with the Drools integration for business rule tasks in the Flowable Engine.

Do you have an idea how you can make the process variables available in the script?

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [June 11, 2017, 7:08pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/11 "2017-06-11T19:08:51Z")

</div>

Hi.  
I t take some time but the job is done 🙂. Here is PR:  
[https://github.com/flowable/flowable-engine/pull/421](https://github.com/flowable/flowable-engine/pull/421)

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [June 13, 2017, 2:27pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/12 "2017-06-13T14:27:05Z")

</div>

Hi Filip,

Thanks for the PR, merged it.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![ilgrosso](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ilgrosso/32/116_2.png) [@ilgrosso](https://forum.flowable.org/u/ilgrosso)\
**Post date:** [June 13, 2017, 2:45pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/13 "2017-06-13T14:45:57Z")

</div>

This sound great, thanks!

Two questions:

1. any chance to backport it to 5.X?
2. how to enable the new feature?

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [June 13, 2017, 8:36pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/14 "2017-06-13T20:36:56Z")

</div>

Hi.  
Ad 1. I will check it if will be helpful.  
Ad 2. There is no need to enable it. Library is a part of flowable web apps. Script will be treated as static if script format is set to `groovy-static`.  
Example:

```
<scriptTask id="theScriptTask" name="Execute script" scriptFormat="groovy-static" flowable:resultVariable="a">
  <script>
    int sum = 0
    for ( i in inputArray ) {
      sum += i
    }
    execution.setVariable("sum", sum)
    String a = "abc".toUpperCase()
  </script>
</scriptTask>

```

Best regards  
Filip

---

<div class="post-metadata">

**Author:** ![PHH](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/phh/32/94_2.png) [@PHH](https://forum.flowable.org/u/PHH)\
**Post date:** [June 13, 2017, 8:52pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/15 "2017-06-13T20:52:11Z")

</div>

Nice work, Filip. Really appreciate the effort for the contribution.

Cheers  
Paul.

---

<div class="post-metadata">

**Author:** ![ilgrosso](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ilgrosso/32/116_2.png) [@ilgrosso](https://forum.flowable.org/u/ilgrosso)\
**Post date:** [June 14, 2017, 8:02am UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/16 "2017-06-14T08:02:37Z")

</div>

1. Cool, I’ll keep watching this thread for news
2. Agree, so the key to enable is using `groovy-static` rather than `groovy`

Thanks!

---

<div class="post-metadata">

**Author:** ![fgroch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fgroch/32/66_2.png) [@fgroch](https://forum.flowable.org/u/fgroch)\
**Post date:** [June 19, 2017, 7:36pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/17 "2017-06-19T19:36:51Z")

</div>

Hi.  
Which branch should I use to implement static compilation for version 5.X, `flowable5`?

Best regards  
Filip

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [June 19, 2017, 7:38pm UTC](https://forum.flowable.org/t/is-it-possible-to-compile-groovy-script-task-statically/300/18 "2017-06-19T19:38:19Z")

</div>

Hi Filip, the flowable5 branch is what you’re looking for: [https://github.com/flowable/flowable-engine/tree/flowable5](https://github.com/flowable/flowable-engine/tree/flowable5)
