Long Tran
04/01/2022, 7:48 AMorg.gradle.api.InvalidUserCodeException: Only one of the JVM targets can be configured to work with Java. The target 'common' is already set up to work with Java; cannot setup another target 'dev'
Dragos Rachieru
04/01/2022, 8:30 AMcommon
your common module for interfaces
dev
mock
sit
uat
prod
All of these should be depending on common
and implement the interfaces in their own waylhwdev
04/01/2022, 9:43 AMkotlin.mpp.enableGranularSourceSetsMetadata=true
) and insert dependsOn
.Big Chungus
04/01/2022, 10:03 AMLong Tran
04/01/2022, 10:15 AMBig Chungus
04/01/2022, 10:16 AMLong Tran
04/01/2022, 10:23 AMwithJava()
from my desktop app, it will leave the message
Unable to find Gradle tasks to build: [:desktopApp:devMain].
Build mode: COMPILE_JAVA.
Tests: All.
and nothing happen, but withJava()
made it runBig Chungus
04/01/2022, 10:24 AMLong Tran
04/02/2022, 6:57 AMDragos Rachieru
04/04/2022, 7:49 AMcommon/src/commonMain/ExampleRepository.kt
interface ExampleRepository.kt {
fun getExamples(): List<String>
}
dev/src/commonMain/ExampleRepositoryImpl.kt
class ExampleRepositoryImpl(
private val devNetworkSource: NetworkSource
) : ExampleRepository {
override fun getExamples(): List<String> = devNetworkSource.fetch()
}
mock/src/commonMain/ExampleRepositoryImpl.kt
object ExampleRepositoryMock : ExampleRepository {
override fun getExamples(): List<String> = List(10) { "Mock $it" }
}
dev/build.gradle.kts
implementation(":common")
mock/build.gradle.kts
implementation(":common")
app/build.gradle.kts
implementation(":common")
implementation(":dev")
implementation(":mock")
app/src/main/kotlin/ExampleRepositoryProvider.kt
...
fun provideExampleRepository(appType: AppType): ExampleRepository {
return when(appType) {
AppType.Mock -> ExampleRepositoryMock
AppType.Dev -> ExampleRepositoryImpl(createDevNetworkSource())
}
}
...
Long Tran
04/04/2022, 12:48 PM