# Custom Keyword plugin with external dependency

**URL:** <https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500>\
**Category:** Integrations\
**Tags:** plugins, katalon-studio\
**Created:** [March 25, 2020, 3:54pm UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500 "2020-03-25T15:54:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DummyAutomation](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DummyAutomation](https://forum.katalon.com/u/DummyAutomation)\
**Post date:** [March 25, 2020, 3:54pm UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500/1 "2020-03-25T15:54:39Z")

</div>

Hi,

Im trying to create an Custom keywords plugin. It turns out that my keyword will use some external jars. In this case i will use org.apache.poi jar that i already added to Driver folder. **My build.gradle** looks like

```
 plugins {
  id 'java'
  id 'groovy'
  id 'com.github.johnrengelman.shadow' version '4.0.4'
  id "com.katalon.gradle-plugin" version "0.0.6"
}

repositories {
  jcenter()
  mavenCentral()
}

sourceSets {
  main {
    groovy {
      srcDirs = ['Keywords', 'Include/scripts/groovy']
      srcDir 'Libs'
    }
  }
}

shadowJar {
  exclude 'Temp*.class'
}

katalon {
  dependencyPrefix = "com.katalon"
  minimize = false
}

jar {
    from fileTree("$buildDir/dependencies/")
}

task extractDependencies(type: Sync) {
    dependsOn configurations.compile

    from (configurations.compile.collect {
        zipTree(it)
    })

    exclude 'META-INF/**'

    into "$buildDir/dependencies/"
}

jar.dependsOn extractDependencies

```

and my **katalon-plugin.json** look like

```
{
  "keywords": ["keywordName"]
}

```

I do not added an package because is to ugly when we call “Custom Keyword” - com.test.name1.name2.etc.keywordName

Note that in build folder i create the folder “dependencies” and added the same jar’s that i added into Katalon Driver folder.

But when i add the generated plugin into “Plugins” folder from another project an error always appear "

```
com.kms.katalon.plugin.models.ReloadPluginsException: Unexpected error occurs during executing reload plugins
	at com.kms.katalon.plugin.service.PluginService.reloadPlugins(PluginService.java:253)
	at com.kms.katalon.composer.handlers.ReloadPluginsHandler$1.run(ReloadPluginsHandler.java:79)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at java_util_List$get$0.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate.getParameterName(CustomKeywordTemplate.groovy:177)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate$getParameterName$0.callStatic(Unknown Source)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate.getInitialExpression(CustomKeywordTemplate.groovy:155)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate$getInitialExpression.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)
	at groovy.tmp.templates.GStringTemplateScript23$_getTemplate_closure1$_closure3$_closure4$_closure5.doCall(GStringTemplateScript23.groovy:18)
etc....

```

Can anyone help me with this problem?

Have a nice day.

---

<div class="post-metadata">

**Author:** ![DummyAutomation](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DummyAutomation](https://forum.katalon.com/u/DummyAutomation)\
**Post date:** [March 25, 2020, 4:52pm UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500/3 "2020-03-25T16:52:41Z")

</div>

Some how i did manage to create. This error is kinda stupid, cuz in my Custom Keyword i did have like this:

```auto
@Keyword
public void KeywordName(String param1,String param 2, String[] param3,String[] param4){
      MainOperation.keywordNameMethod(param1,param2,param3,param4)
}

```

Then in MainOperation the same method signature as the keyword.

```auto
 public void keywordNameMethod(String param1,String param 2, String[] param3,String[] param4){
         ....
        for(int i=0; i<param3.length; i++){
              ..... 
param4[i]
           }
    }

```

Then i did change the signature to be an Map\<String, String\> and with the for loop i did ```  
**for (Map.Entry\<String, String\> entry : map.entrySet())**

So the main reason for the **Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0** i think was that param3.length some how.

I did make an test making a keyword that called the same method but without that for loop and it worked.

I hope this solution helps other people with the same issue.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 27, 2020, 11:57am UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500/4 "2020-04-27T11:57:06Z")

</div>

> [@DummyAutomation](#):
>
> , String param 2,

You have a single whitespace between ‘`param`’ and ‘`2`’, but why?

This single whitespace will confuse Groovy. Unfortunately Groovy failed to blame your coding mistake, got panicked, threw an Exception that doesn’t make sense.

You should write:

```auto
, String param2,

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 27, 2020, 9:49pm UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500/5 "2020-04-27T21:49:50Z")

</div>

Just for your interest. Groovy allows you to assign default values to method arguments. Following snippet is valid in Groovy:

```auto
public void keywordNameMethod(String param1 = "", String param2 = "", String[] param3 = new String[0], String[] param4 = new String[0]) {

```

It is a goodness of Groovy as [https://mrhaki.blogspot.com/2009/09/groovy-goodness-parameters-with-default.html](https://mrhaki.blogspot.com/2009/09/groovy-goodness-parameters-with-default.html) describes. Java doesn’t support this.

I think that `String param 2`, which is invalid, looks too similar to `String param = ""`, which is valid. That is the reason why Groovy got panicked.

---

<div class="post-metadata">

**Author:** ![DummyAutomation](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@DummyAutomation](https://forum.katalon.com/u/DummyAutomation)\
**Post date:** [May 15, 2020, 3:51pm UTC](https://forum.katalon.com/t/custom-keyword-plugin-with-external-dependency/41500/6 "2020-05-15T15:51:23Z")

</div>

Hi @kazurayam ,

Yes i know. I really don’t know why i post like String param 2, when in my code i have String param2.

Have a nice weekend.

Thank you.
