Excluding specific classes out of the plugin jar

I followed the instruction presented by How to develop Custom Keywords Plugins and successfully created a jar as a Cutom Keyword as plugin:

My junit4ks-all.jar contained the following:

M Filemode      Length  Date         Time      File
- ----------  --------  -----------  --------  -----------------------------------------------------------------------------
  drwxr-xr-x         0  11-Mar-2019  09:45:32  META-INF/
  -rw-r--r--        59  11-Mar-2019  09:45:32  META-INF/MANIFEST.MF
  drwxr-xr-x         0  11-Mar-2019  09:45:30  com/
  drwxr-xr-x         0  11-Mar-2019  09:45:30  com/example/
  -rw-r--r--      5655  11-Mar-2019  09:45:30  com/example/MiniScreenshotDriver.class
  -rw-r--r--      5754  11-Mar-2019  09:45:30  com/example/MiniScreenshotDriverTest.class
  drwxr-xr-x         0  11-Mar-2019  09:45:30  com/kazurayam/
  drwxr-xr-x         0  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/
  -rw-r--r--       398  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/IgnoreRest.class
  -rw-r--r--      4148  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/IgnoreRestHelper.class
  -rw-r--r--      3746  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/IgnoreRestRule$1.class
  -rw-r--r--      4780  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/IgnoreRestRule.class
  -rw-r--r--      4397  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/IgnoreRestSupportRunner.class
  -rw-r--r--       393  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywords$JUnitRunnerResult.class
  -rw-r--r--      5463  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywords$JUnitRunnerResultImpl.class
  -rw-r--r--      6275  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywords$RunListener4KS.class
  -rw-r--r--      5909  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywords$_runWithJUnitRunner_closure1.class
  -rw-r--r--      7323  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywords.class
  -rw-r--r--      3466  11-Mar-2019  09:45:30  com/kazurayam/junit4ks/JUnitCustomKeywordsTest.class
  drwxr-xr-x         0  11-Mar-2019  09:45:30  junittutorial/
  -rw-r--r--      5144  11-Mar-2019  09:45:30  junittutorial/Calculator.class
  -rw-r--r--      4330  11-Mar-2019  09:45:30  junittutorial/CalculatorTest.class
  -rw-r--r--      4436  11-Mar-2019  09:45:30  junittutorial/CalculatorWithIgnoreRestTest.class
  -rw-r--r--      2996  11-Mar-2019  09:45:30  junittutorial/Greeter.class
  -rw-r--r--      3615  11-Mar-2019  09:45:30  junittutorial/GreeterTest.class
  -rw-r--r--       284  11-Mar-2019  09:45:30  katalon-plugin.json
- ----------  --------  -----------  --------  -----------------------------------------------------------------------------
                 78571                         26 files

I noticed that

  1. I want to exclude com/example/**/.class
  2. I want to exclude junittutorial/**/*.class
  3. I want to exclude **/*Test.class

How can I expression my intention in the build.gradle file.

1 Like

Hi @kazurayam,

Try to add the followings to your build.gradle file:

shadowJar {
    exclude 'com/example/**/*.class'
    exclude 'junittutorial/**/*.class'
    exclude '**/*Test.class'
}
1 Like

@sonpham,

Thank you for your reply.

1 Like

@devalex88,

How to package Custom Keyword as plugin requires me to create Keywords/katalon-plugin.json file, for example:

{
  "keywords": ["com.katalon.plugin.keyword.excel.ExcelReadKeywords", "com.katalon.plugin.keyword.excel.ExcelWriteKeywords"]
}

I thought that katalon-plugin.json file is meant to express which class to be included in the plugin’s jar to be created.

I created my katalon-splugin.json as https://github.com/kazurayam/junit4ks/blob/master/Keywords/katalon-plugin.json

{
    "keywords": [
        "com.kazurayam.junit4ks.IgnoreRest",
        "com.kazurayam.junit4ks.IgnoreRestHelper",
        "com.kazurayam.junit4ks.IgnoreRestRule",
        "com.kazurayam.junit4ks.IgnoreRestSupportRunner",
        "com.kazurayam.junit4ks.JUnitCustomKeywords"
    ]
}

But the generated jar file contains unwanted *Test.classes etc. I am wondering what katalon-plugin.json is designed for.

1 Like

@kazurayam,

The katalon-plugin.json is the metadata of plugin when installing to katalon studio. It doesn’t relate to packing plugin jar process.
For example, you can package 5 keywords in jar but only want to publish 3 of it.

I have a question (or requirement) how to specify which class to be included in the plugin’s jar, eclude out of the jar. I expected that the katalon-plugin.json is meant for it. Thong answered to it as:

Currently all of classes under the Keywords directory and Include/scripts/grooovy is included in the jar. I would rather like to specify which class to include and exclude.

In short, I want to be able to write as follows (synonim to the Jar task of Gradle):

katalon {
    dependencyPrefix = "com.katalon"
    minimize = false
    include('com/kazurayam/junit4ks/*.groovy')
    exclude('**/*Test.groovy')
}
1 Like

Please take a look at https://github.com/katalon-studio/katalon-studio-excel-custom-keywords-plugin/blob/master/build.gradle.

shadowJar {
  exclude 'Temp*.class'
}

In your case it would be exclude '**/*Test.class'.