and the commons module has a lot of other third party dependencies
when I create a new project that depends on the app project, the build is trying to load jar for the commons module. how can I create one jar for all sub modules and let it be the only one that loaded when I add the app project as dependency?
What you try to achieve looks like more or less nodejs module dependency management in my mind: each dependency should come with its own dependencies bundled.
Due to the JVM classloader, things work differently with Java, you may experience weird issues if several dependencies bring into the classpath different versions of a same third party lib. To avoid these issues, most developers use – and expect that the third parties they depend on also use – conflict resolution strategies to select the best version of a common dependency.
Nevertheless, if you still want to navigate that way, here is how I did it within the app project:
plugins {
id("java")
}
repositories {
mavenCentral()
}
dependencies {
implementation "junit:junit:4.12" // just an example
}
// jar with dependencies
jar {
from sourceSets.main.output
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}