Can Gradle handle a build directory structure that does not conform default conventions?
Asked Answered
P

3

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?

Physician answered 31/3, 2010 at 8:33 Comment(0)
L
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.

Luciusluck answered 2/4, 2010 at 8:44 Comment(0)
E
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'
    }
}
Enenstein answered 6/5, 2016 at 6:12 Comment(1)
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!Lightning
Y
4

Try:

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

or

sourceSets {
    main.java.srcDirs += 'src/java'
    main.resources.srcDirs += 'src/resources'
}
Yancey answered 16/11, 2017 at 5:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.