A concept used by the Gradle build system, to divide the source code into parts for which the build process can be configured separately.
Questions tagged [source-sets]
82 questions
118
votes
10 answers
How do I add a new sourceset to Gradle?
I want to add integration tests to my Gradle build (Version 1.0). They should run separately from my normal tests because they require a webapp to be deployed to localhost (they test that webapp). The tests should be able to use classes defined in…

Spina
- 8,986
- 7
- 37
- 36
60
votes
6 answers
Gradle flavors for android with custom source sets - what should the gradle files look like?
I've got an old eclipse project I've moved into android studio and setup to use flavors. It seemed to be working fine till I started trying to use different java files between my flavors.
My project setup is this:
ProjectRoot
+-…

AdamWardVGP
- 670
- 1
- 5
- 13
40
votes
2 answers
Shared srcDirs between test and androidTest, unresolved references after upgrade to Android Studio Chipmunk (IntelliJ 2021.2.1)
I just upgraded from Bumblebee to Chipmunk, and I am having multiple dependency-resolution issues in my instrumented androidTests.
These are what my source sets look like:
sourceSets {
test.java.srcDirs += 'src/testShared/kotlin'
…

Sean Blahovici
- 5,350
- 4
- 28
- 38
35
votes
2 answers
Android gradle buildTypes: Duplicate class
I'm converting my app to use gradle, and I'm trying to use the buildTypes. I have a Constants class which I wish to modify for my release build. So I have a file at src/main/java/my/package/name/Constants.java and at…

Arne517
- 825
- 2
- 8
- 14
19
votes
1 answer
Gradle: custom source set as dependency for the main and test ones
I've created custom source set in Gradle project to keep all generated code:
sourceSets {
generated {
java {
srcDir 'src/generated/java'
}
resources {
srcDir 'src/generated/resources'
}
}
}
I want to make the result…

Anton Moiseev
- 2,834
- 4
- 24
- 30
17
votes
3 answers
Kotlin: java.lang.NoSuchMethodError in tests
Is it possible to use Kotlin package functions and package properties in different sourcesets? When I try to do so, I have NoSuchMethodError thrown.
Example
I have Gradle project with Kotlin code and two sourcesets in it, main and test.
In main, I…

hotkey
- 140,743
- 39
- 371
- 326
16
votes
4 answers
SharedTest got warning "Duplicate content root detected" on Android Studio Chipmunk
After upgrade to Android Studio Chipmunk, my test failed because I can't access file inside shared folder that defined in build.gradle like this.
sourceSets {
androidTest.java.srcDirs += "src/sharedTest/java"
test.java.srcDirs +=…

Ahmad Arif Faizin
- 173
- 1
- 7
15
votes
2 answers
gradle get resources default output directory
Gradle: how to get default resources output dir?
println sourceSets.main.resources.outputDir
Error:
Needs to set a non-null value before it can be retrieved

eastwater
- 4,624
- 9
- 49
- 118
13
votes
1 answer
Gradle sourceSet depends on another sourceSet
This Question is similar to Make one source set dependent on another
Besides the main SourceSet I also have a testenv SourceSet.
The code in the testenv SourceSet references the main code, therefor I need to add the main SourceSet to the…

Adrodoc
- 673
- 10
- 19
12
votes
1 answer
The SourceSet 'commonTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?
Seemingly the same root cause as this question, but the answer there will not work for me. I have a custom source set called commonTest that I use for sharing certain test utility code across the test and androidTest source sets. Here is my relevant…

AutonomousApps
- 4,229
- 4
- 32
- 42
10
votes
1 answer
Exclude assets from debug build on Flutter
I have 8000+ files named (1.txt, 2.txt, 3.txt, etc) on my /assets/files folder. However I don't need all of them for my debug build. I only need the first 30 of them. Indeed, if I leave all those files on the assets folder the build time is…

Daniel
- 708
- 1
- 8
- 18
8
votes
1 answer
Gradle: using resources in a dependency jar as a sourceset
Suppose I have a build.gradle thus:
dependencies {
compile 'com.group:some-app:1.0.1'
compile 'com.group:some-app:1.0.1:sources'
}
sourceSets {
main {
other {
srcDir 'src/main/other'
}
}
}
So…

Stewart
- 17,616
- 8
- 52
- 80
6
votes
1 answer
Get compiled .class output directory in Android Gradle task
I'm creating a Gradle task for my Android project that needs to know the path to the compiled .class files. How can I get this path? I've found suggestions (here and here; also see the Gradle docs for SourceSet) that sourceSets.main.output.classDir…

Dan Getz
- 8,774
- 6
- 30
- 64
5
votes
2 answers
Define a sourceset for all java sub-projects
I wonder if it is possible to define a source set in gradle (e.g. integrationTests) that can be applied to all sub-projects that use the 'java' plugin?
Something like
sourceSets {
integTest {
java.srcDir…

u6f6o
- 2,050
- 3
- 29
- 54
4
votes
1 answer
Replace an XML file for each flavour in android
I am trying to integrate Braze into my application for push notification. Braze need us to create a braze.xml file inside src/main/res/values where we add the API key and other braze related stuff(here is the documentation).
Now I need to…

hushed_voice
- 3,161
- 3
- 34
- 66