Reputation: 2475
On Gradle 6.1.1, how to go around adding sourceSets for android project?
The answer on other questions doesn't work anymore, getByName("name")
returns error with SourceSet with name 'main' not found.
The official document said to use
sourceSets {
main {
java {
srcDir("thirdParty/src/main/java")
}
}
}
However, there are over 20 main that has to be imported and I'm not sure which one is correct.
Upvotes: 3
Views: 7362
Reputation: 2417
I'm using gradle 6.5.1, however documentation suggest, that is should also work for you, try:
sourceSets {
named("main") {
java.srcDir("../buildSrc/src/main/java")
}
}
It's also works for build types (debug/release), flavours etc.
Reason for this is that groovy can somehow interpret itself and knows main
etc., but on gradle kts, you have call it using named
for already existing, or getByName
, create
etc. base on need.
Similiar situation is for implement
and api
in groovy you can just use implementationDebug
to attach it only for debug version, but in kotlin dsl you have to call it as a string "implementationDebug"
, because there is no such function
----- PS -----
If named
, getByName
not works for you, then try to experiment with findByName
and create
Upvotes: 9