Bundling external dependency jars in serviceloader jar with TestNG Listeners

18 views
Skip to first unread message

Arun Kumaresan

unread,
Oct 9, 2017, 11:06:19 PM10/9/17
to testng-users
Hi,

I have a question related to bundling external jars dependencies along with my serviceloader jar.

My current folder structure is 

META-INF/service/org.testng.ITestNGListener
com/mycompany/MyListener.class (that implements ISuiteListener)

But MyListener.class has reference/dependency on rest-assured for running some REST queries.

How do I bundle up these external jars (like rest-assured) along with my serviceloader jar (containing my customer listeners) so I dont have to bother about finding all the other dependencies and include them in my classpath. In a regular project those are taken care my pom/maven.

Any help on this is highly appreciated.

Regards,
Arun Kumaresan.

Krishnan Mahadevan

unread,
Oct 9, 2017, 11:09:29 PM10/9/17
to testng...@googlegroups.com

Based upon your build tool (Maven/Gradle/Ant) you would have to do this accordingly.

Basically you go about building an uber jar (jar of jars) 

 

If you were using Maven as your build tool, you can make use of either the assembly plugin or the shade plugin to do this.

Here’s a tutorial that shows how to use the maven shade plugin to build an uber jar : http://www.avajava.com/tutorials/lessons/how-do-i-build-a-jar-file-that-contains-its-dependencies.html

 

If you are using Gradle as your build tool, you can refer here : https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/

 

If you are not going to be deploying your jar anywhere (like how they do it for a web app or a restful service) then you don’t need an uber jar.

 

You basically have to just publish your artifact (as a gradle artifact or as a maven artifact) and after that Maven/Gradle should take care. Am guessing you are perhaps not using any build tool. If that’s the case, now is the time to switch to using one.

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages