Build a Single jar with multiple main classes

Can I build jar with multiple main classes(under same package) so that I can run the jar using the below command ?

java -cp myjar.jar MainclassName

I am new to gradle and I learned to buid a jar from sigle main class. I couldnt find a solution for building multiple main classes.

Just build a jar and specify the main class in the command as shown in your example.

The jar main class can be only one and it is being used when you specify java -jar (not java -cp). BTW this is not a Gradle question - this is how Java works.

Yes This is a gradle question. I am not asking which command we need to run a jar. And also we can have multiple main classes inside a single jar. All I asked is how to build that jar with multiple main classes.