Questions about sourcesets, dependencies, and multiproject builds

Hi, refactoring some old java code, I had about 300 projects spit over about a dozen eclipse workspaces (with lots of multiple copies of stuff). I consolidated these into 6 workspaces .

I refactored 100 projects into one eclipse workspace that has mostly just java code (always in src/ and tst/). i put the source code for each project into a top level package. these all work fine in eclipse.

I made a gradle library project. i plan to add a sub project with the same name as each top level package. i am hoping to point the source directory to the parent of the top level package.

So all of the source directories will point to the main project and many of the subprojects (top level packages) will have their own build file in the subproject/top level package directory.

Does this sound like a sane idea?

Also, it’s not clear how to do some of the common things (please see below) like source sets and dependencies. any advice on the current canonical way to do this stuff will be appreciated.


// stuff that can be done different ways
// source sets

sourceSets {
main { java { srcDir ‘src’ }}
test { java { srcDir ‘test’ }} = [“src”,“examples”]
main.resources.srcDirs = [“resources”]

sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file(‘src/integration-test/java’)
resources.srcDir file(‘src/integration-test/resources’)

// jar with source

task srcJar(type: Jar) {
classifier = ‘src’
from sourceSets.main.allGroovy
java { withSourcesJar() }

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = ‘sources’
from sourceSets.main.allSource
artifacts {
archives sourcesJar // may not usually want this?
//archives javadocJar

// dependencies

dependencies { // older
compile project(’:tabletcore’)
compile fileTree(dir: ‘lib’, includes: [’*.jar’])
testCompile group: ‘junit’,name:‘junit’,version: ‘4.12’
dependencies { // newer?
testImplementation ‘org.junit.jupiter:junit-jupiter-api:5.6.2’ // Use JUnit Jupiter API for testing.
testRuntimeOnly ‘org.junit.jupiter:junit-jupiter-engine’ // Use JUnit Jupiter Engine for testing.
api ‘org.apache.commons:commons-math3:3.6.1’ // This dependency is exported to consumers, that is to say found on their compile classpath.
implementation ‘’ // This dependency is used internally, and not exposed to consumers on their own compile classpath.