One easy way to achieve what you want is to create a multi-project assembly with two subprojects (foobase and foo2), where the source kits for foo2 are configured to contain the foobase source kits in addition to their own sources,
To get different dependencies for artifacts, you just need to declare the dependencies section differently in subprojects.
To test this, I created a multiproject assembly with one java file in each subproject. To simplify the output here, the build.gradle root file contains everything, including special subproject settings. However, in "real life" I always added specific subproject configurations to the build.gradle file at the correct subproject level.
The gradle build file contains
- Adding source sets from foobase to foo2
- Different dependencies in two projects
- Deploy to a local maven repository (to make sure pom are created correctly)
- Additional IDE Plugins for IntelliJ IDEA and Eclipse
In general, I did the following:
Project structure
build.gradle => root project build file settings.gradle => specification of included subprojects foo2\ => foo2 subproject folder src\ main\ java\ Foo2.java => Empty class foobase\ => foobase subproject folder src\ main\ java\ FooBase.java => Empty class
settings.gradle
include ':foobase', ':foo2'
build.gradle
allprojects { apply plugin: 'idea' apply plugin: 'eclipse' group = 'org.foo' version = '1.0' } subprojects { apply plugin: 'java' apply plugin: 'maven' repositories { mavenCentral() } uploadArchives { it.repositories.mavenDeployer { repository(url: "file:///tmp/maven-repo/") } } } project(':foobase') { dependencies { compile 'log4j:log4j:1.2.13' } } project(':foo2') { dependencies { compile 'log4j:log4j:1.2.16' } sourceSets.main.java.srcDirs project(':foobase').sourceSets.main.java sourceSets.main.resources.srcDirs project(':foobase').sourceSets.main.resources sourceSets.test.java.srcDirs project(':foobase').sourceSets.test.java sourceSets.test.resources.srcDirs project(':foobase').sourceSets.test.resources }
Note that I have added source directories for resources and tests. You can omit the last three lines if this is not required.
To check the assembly:
- Make sure the two jar files contain all the classes you need.
- Make sure the two deployed maven pom have the correct dependencies.
In my case:
foobase-1.0.jar contains only FooBase.classfoo2-1.0.jar contains both FooBase.class and Foo2.class- the loaded
foobase-1.0.pom contains a dependency on log4j-1.2.13 - the downloaded
foo2-1.0.pom contains a dependency on log4j-1.2.16
source share