Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refering to main class of a sub-project in a multi-project gradle setup

Tags:

java

gradle

I'm working on a multi-project gradle setup, where the structure is like below:

pipeline-jobs                       // root folder
├── gradle.properties
├── settings.gradle
├── build.gradle
└── partition-by-users              // sub-project
    ├── com.client.dataPipelineJobs.partitionByUsers
    │   └── PartitionByUsers.java   // has the main() method
    └── build.gradle

pipeline-jobs is the root project folder and for now I've only one subproject called partition-by-users. In future many more sub-projects will get added. I want to build runnable jars for all these sub-projects. My build.gradle file under partition-by-users sub-project looks like below:

jar {
  zip64 = true
  manifest {
    attributes('Main-Class': 'com.client.dataPipelineJobs.partitionByUsers.PartitionByUsers')
  }
  from {
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  }
}

Now from the root project dir if I execute gradle jar command and then run the jar file, it throws the following error:

Could not find or load main class com.client.dataPipelineJobs.partitionByUsers.PartitionByUsers

I'm not able to find out the root cause behind this. What am I missing here? I've tried changing the manifest with attributes('Main-Class': partition-by-users.com.client.dataPipelineJobs.partitionByUsers.PartitionByUsers) but that didn't help.

Update: I think there's some issue with building the fat-jar. Building the jar without the dependencies solve the problem, but then probably I've find out a different way of preparing the fat-jar.

like image 791
Bitswazsky Avatar asked Nov 25 '25 23:11

Bitswazsky


1 Answers

I found out the answer in this SO thread. Whoever bumps onto this page, please look at the answer provided by @blootsvoets in the previous link.

The basic idea is to use the same manifest in jar and fatJar tasks.

like image 94
Bitswazsky Avatar answered Nov 27 '25 12:11

Bitswazsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!