# How to resolve external dependencies for a Plugin

**URL:** <https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346>\
**Category:** Integrations\
**Tags:** plugins, katalon-studio\
**Created:** [March 18, 2019, 12:24am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346 "2019-03-18T00:24:04Z")\
**Posts on this page:** 16\
**Page:** 1

<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:** [March 18, 2019, 12:24am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/1 "2019-03-18T00:24:04Z")

</div>

I have a question how to resolve external dependencies for a Plugin.

I have a Custom Keyword named [com.kazurayam.ksbackyard.ScreenshotDriver](https://github.com/kazurayam/ksbackyard/blob/master/Keywords/com/kazurayam/ksbackyard/ScreenshotDriver.groovy). This enables you to take full-page screenshots of web pages. Another post [How to package Custom Keyword as Plugin](http://forum.katalon.com/t/how-to-package-custom-keyword-as-plugin/20321) showed us how to make a jar of custom keywords. Following this instruction, I could make a jar which contains the ScreenshotDriver class.

My ScreenshotDriver class depends on an external Java library [aShot](https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot/1.5.4). How can I resolve the external dependency when I install the Plugin into another Katalon Project? Does Katalon 6.x.x resolves the dependencies to aShot automatically? Or do I have to download the jar of aShot from Maven Central and deploy it into the Drivers directory in into the project?

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 18, 2019, 12:45am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/2 "2019-03-18T00:45:14Z")

</div>

You have to add dependencies to `build.gradle` the same way you use the Gradle task `katalonCopyDependencies`.

---

<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:** [March 18, 2019, 12:46am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/3 "2019-03-18T00:46:58Z")

</div>

Any Example?

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 18, 2019, 12:49am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/4 "2019-03-18T00:49:29Z")

</div>

I’ll add one in a few hours.

---

<div class="post-metadata">

**Author:** ![duyluong](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/duyluong/32/1116_2.png) [@duyluong](https://forum.katalon.com/u/duyluong)\
**Post date:** [March 18, 2019, 2:39am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/5 "2019-03-18T02:39:46Z")

</div>

Hi @kazurayam,

Please add this script in `build.gradle` file to embed your custom keyword plugin dependencies into the execution classpath:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 18, 2019, 5:42am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/6 "2019-03-18T05:42:24Z")

</div>

> [@kazurayam](#):
>
> Any Example?

@duyluong’s solution is one way to achieve this.

If your dependencies are on Maven Central already, you can add them to `build.gradle`. See the following example:

> **[GitHub - katalon-studio/katalon-studio-zip-keywords-plugin](https://github.com/katalon-studio/katalon-studio-zip-keywords-plugin)**
>
> Contribute to katalon-studio/katalon-studio-zip-keywords-plugin development by creating an account on GitHub.

> <https://github.com/katalon-studio/katalon-studio-zip-keywords-plugin/blob/master/build.gradle>

There is another benefit. Your dependencies will be [repackaged](http://repackage.org) in order to avoid conflicts with other plugins as much as possible.

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/e/ed602f5615c743d420419d0bb8ddf3e8f5e0084e.png)

---

<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:** [March 18, 2019, 5:52am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/7 "2019-03-18T05:52:21Z")

</div>

> [@duyluong](#):
>
> 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

I tried this, but I could not find any `build/dependencies` folder created. No jar file, of course.

> [@duyluong](#):
>
> from (configurations.compile.collect {

In the build.gradle file, I have do not have

```auto
dependencies {
    compile xxxx xxxx xxxx
}

```

The aShort jar file is located in the `<projectDir>/Drivers` folder. How can a gradle build process know where the aShot.jar is there?

---

<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:** [March 18, 2019, 5:54am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/8 "2019-03-18T05:54:13Z")

</div>

@devalex88,

> [@devalex88](#):
>
> If your libraries are on Maven Central already, you can add it to `build.gradle` .

Sorry, I do not see what you mean. In the example code, where do you have **your libraries** on Maven Central described?

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 18, 2019, 6:00am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/9 "2019-03-18T06:00:25Z")

</div>

I’ve changed it to “dependencies” e.g. AShot. I used Zip4J in the above example.

---

<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:** [March 18, 2019, 6:21am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/10 "2019-03-18T06:21:53Z")

</div>

I added

```auto
dependencies {
    // https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot
    compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'

```

and executed

```auto
$ gradle katalonPluginPackage

```

Then, a huge size of jar file was created. 6.8MB. It contained all of classes including Groovy, WebDriver etc. It seems that all of the class files in the `project.configurations.compile` are included in the jar. I do not think this is a favorable result.

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 18, 2019, 9:03am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/11 "2019-03-18T09:03:23Z")

</div>

It’s because AShot depends on Selenium, i.e Selenium is a transitive dependency. Since Katalon already contains Selenium, this dependency should be excluded.

> **[GitHub - katalon-studio/katalon-studio-ashot-keywords-plugin](https://github.com/katalon-studio/katalon-studio-ashot-keywords-plugin)**
>
> Contribute to katalon-studio/katalon-studio-ashot-keywords-plugin development by creating an account on GitHub.

```nohighlight
dependencies {
  compile 'ru.yandex.qatools.ashot:ashot:1.5.4'
}

configurations {
  compile.exclude group: 'org.seleniumhq.selenium'
}

```

---

<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:** [March 18, 2019, 9:12am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/12 "2019-03-18T09:12:40Z")

</div>

Thank you for your response. I will try.

---

<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:** [March 19, 2019, 12:32am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/13 "2019-03-19T00:32:32Z")

</div>

@devalex88

It worked fine.

Here I copy&pasted my build.gradle file for my ksbackyard project.

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

ext {
    groovyVersion = '2.4.7'
}

configurations {
    generateDocs

    compile.exclude group: 'org.seleniumhq.selenium'
    compile.exclude group: 'commons-io'
    compile.exclude group: 'com.google.code.gson'
    compile.exclude group: 'org.hamcrest'
    compile.exclude group: 'junit'
    compile.exclude group: 'org.mockito'
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot
    compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'

    generateDocs "org.codehaus.groovy:groovy-all:${groovyVersion}"
}

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

shadowJar {
    exclude 'Temp*.class'
}

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

task groovydoc(type: Groovydoc, overwrite:true) {
    source = sourceSets.main.groovy
    classpath = configurations.compile
    groovyClasspath = project.configurations.generateDocs
    include 'com/kazurayam/ksbackyard/*'
    exclude '**/*Test.groovy'
}
task publishGroovydoc(type: Copy) {
    from 'build/docs/groovydoc'
    into 'docs/api'
}
groovydoc.finalizedBy publishGroovydoc

```

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 19, 2019, 12:49am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/14 "2019-03-19T00:49:24Z")

</div>

Great news! We are looking forward to your awesome Keywords 😄.

> [@kazurayam](#):
>
> dependencyPrefix = “com.katalon”

One minor point: this should be your namespace (`com.kazurayam`) so that AShot will be repackaged under `com.kazurayam` and will not clash with other plugins that use different versions of AShot.

---

<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:** [March 19, 2019, 12:51am UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/15 "2019-03-19T00:51:41Z")

</div>

OK,

I did not see what

```auto
katalon {
    dependencyPrefix="...."

```

is for. Now I understand it.

---

<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 24, 2020, 1:43pm UTC](https://forum.katalon.com/t/how-to-resolve-external-dependencies-for-a-plugin/21346/16 "2020-03-24T13:43:24Z")

</div>

This post really save my life 😃
