0

I currently have multiple buildTypes and productFlavors:

freemiumDebug
freemiumRelease
paidVersionDebug
paidVersionRelease

.. and many many more. I want to add a mock buildType. So that I have freemiumMock:

buildTypes {
    mock {
        applicationIdSuffix = ".mock"
    }
}

SomeReaderClass.kt implements GenericReaderInterface.kt and gets injected using Dagger:

app/src/main/com/mycompany/reader/SomeReaderClass.kt
app/src/main/com/mycompany/reader/di/ReaderModule.kt
app/src/main/com/mycompany/reader/GenericReaderInterface.kt

Now I create a mock directory and add MockReaderClass.kt:

app/src/mock/com/mycompany/reader/MockReaderClass.kt
app/src/mock/com/mycompany/reader/di/ReaderModule.kt

The ReaderModule makes the distinction which file to inject:

@Module
class ReaderModule {

    @Provides
    @Singleton
    fun provideReaderModule(): SomeReaderClass = MockReaderClass(context)
}

Now the compiler complains that ReaderModule is twice. I was thinking excluding the directory using sourceSets. Is this the correct approach?

sourceSets {
    main {
        resources {
            exclude 'mock'
        }
    }
}

I cannot remove SomeReaderClass from main because there are a lot of different buildTypes and productFlavors and it's just not possible to copy/paste them everywhere.

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

0 Answers0