I have a multi-module setup for a Java project with following structure.
mainApp
|--> core-module
| |--> src
| |--> build.gradle
|--> implementation group: 'org.apache.axis2', name: 'axis2-kernel', version: '1.7.8'
|--> implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13'
|--> implementation files('libs/some_local.jar')
|--> compile project(":lib-module")
|--> compile project(":lib-another-module")
|--> ...
|
|--> lib-module
| |--> src
| |--> build.gradle
|--> implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
|--> implementation files('libs/another_local.jar')
|--> ...
|--> lib-another-module
| |--> src
| |--> build.gradle
|--> implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|--> implementation files('libs/another_local.jar')
|--> ...
|
|--> settings.gradle
|--> build.gradle
|--> gradle.properties
In mainApp/build.gradle
file I have a 'mentioned' sub-modules as
sourceSets {
main {
java {
srcDirs project('core-module').file("src")
srcDirs project('lib-module').file("src")
srcDirs project('lib-another-module').file("src")
}
}
}
If I build individual sub-module it get compiled successfully but when I run ./gradlew compileJava
at root , it fails with classNotFoundExceptions
from the jars which I've already mentioned in sub-modules
> Task :core-module:compileJava
//successful
> Task :lib-module:compileJava
//successful
> Task :lib-another-module:compileJava
//successful
> Task :compileJava
/.../core-module/src/java/../OAuthUtils.java:12: error: package org.apache.http does not exist
import org.apache.http.Header;
...
//FAILED!
Here ./gradlew core-module:compileJava
works perfectly but compilation fails when invoked from root.
- How shall I deal with it?
- Is it because of some local jars referred from file-system?
EDIT
I found that the compilation of root sourceSets{}
which is pointing to child sub-module
is failing and individual sub-module
compilation is successful.
But, I need this sourceSets{}
for creating one monolithic jar of all sub-module
Note:- I'm not creating fatJar
or shadedJar
here, But I need to include all packages from all sub-modules
without dependency jars.