Reputation: 1657
I am new to Gradle and I have a source code location different than what Gradle expects.
Gradle expects to find the production source code under src/main/java
and your test source code under src/main/resources
. How do I configure Gradle to a different source code?
Upvotes: 23
Views: 18290
Reputation: 2360
Using Gradle Kotlin DSL.
This will add directory to already defined set (so you will have both src/main/java
and src-main/main/java
as a result):
sourceSets {
getByName("main") {
java.srcDir("src-main/main/java")
}
}
Use setSrcDirs(Iterable)
to actually replace source set completely:
sourceSets {
getByName("main") {
java.setSrcDirs(listOf("src-main/main/java"))
}
}
Reference: SourceDirectorySet (Gradle API 8.9).
Upvotes: 0
Reputation: 1657
You have to add few lines to build.gradle
:
To replace the default source folders, you will want to use srcDirs instead, which takes an array of the path.
sourceSets {
main.java.srcDirs = ['src/java']
main.resources.srcDirs = ['src/resources']
}
Another way of doing it is:
sourceSets {
main {
java {
srcDir 'src/java'
}
resources {
srcDir 'src/resources'
}
}
}
The same thing is applicable to test folder too.
Upvotes: 38