26

I am working on a + based project that has the following directory structure:

projectRoot/src
projectRoot/classes
projectRoot/conf
projectRoot/webservices

this works perfectly well in but I am looking to migrate to .

Is there a way to define a non-maven directory structure in Gradle or should I be looking to mavenize?

Cœur
  • 37,241
  • 25
  • 195
  • 267
liam.j.bennett
  • 424
  • 1
  • 4
  • 11

3 Answers3

35

It is very easy with Gradle to adapt to any directory structure. See the Working with source sets section of the Gradle User Guide.

RespiteSage
  • 23
  • 1
  • 6
Hans Dockter
  • 529
  • 4
  • 3
14

Example with non-standard project directory structure (custom layout):

sourceSets {
    main {
        java {
            srcDir 'sources/main/java'
        }
        outputDir = file("$workDir/client/program")
        // For older version (now deprecated):
        //output.classesDir = "$workDir/client/program"
    }
    test {
        java {
            srcDir 'sources/test/java'
        }
        outputDir = file("$workDir/client/tests")
        // For older versions (now deprecated):
        //output.classesDir = "$workDir/client/tests"
        //output.resourcesDir = "$workDir/client/tests"
    }
    resources {
        srcDirs 'sources/test/res'
    }
}
Dimitar II
  • 2,299
  • 32
  • 33
  • After hours of searching today, this solved my problem. For some reason the --project-root argument and rootProject.projectDir are ignored? No matter what I do "println project.projectDir" within build.gradle always echos the folder in which build.gradle lives in. Using: srcDir '../../src/main/java" fixed the problem. Thankyou! – KANJICODER May 23 '19 at 01:31
4

Try:

sourceSets {
    main {
        java {
            srcDirs = ['src/java']
        }
        resources {
            srcDirs = ['src/resources']
        }
    }
}

or

sourceSets {
    main.java.srcDirs += 'src/java'
    main.resources.srcDirs += 'src/resources'
}
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203