Open tb-kpabla opened 2 months ago
Hi,
Same issue here.
I'm trying to use io.github.flaxoos:ktor-server-task-scheduling-jdbc:1.2.8
in my ktor android project.
I'd really appreciate this change.
Hi Guys, thanks for your input, and sorry for the late response
@tb-kpabla @Szczypiorek44 could you please share more details, like which jars are conflicting?
I am using the gradle shadow plugin, perhaps i missed some config
In any case, did you try using the various solutions gradle offers?
Hi @Flaxoos
So because every dependency needed by the io.github.flaxoos:ktor-server-task-scheduling-jdbc:1.2.8
is compiled inside the jar, I'm facing the issue of duplicate classes.
I've tried multiple solutions to exclude them, but all methods are failing because those dependencies are not transitive, they are compiled inside the jar - they shouldn't.
Transitive dependency - A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.
So basically when I include your library in my project it should inform gradle in my project which dependencies your library requires and gradle should resolve and download them. This is not happening because they are compiled in the jar.
In my project I'm also using ktor
, krontab
, and some other kotlin dependencies and all of that is giving me duplicate classes error. The error itself is huge, it's hundreds lines of Duplicate class ...
, but here's part of it:
* What went wrong:
Execution failed for task ':sample-app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class _COROUTINE.ArtificialStackFrames found in modules kotlinx-coroutines-core-jvm-1.8.0.jar -> kotlinx-coroutines-core-jvm-1.8.0 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class com.typesafe.config.Config found in modules config-1.4.3.jar -> config-1.4.3 (com.typesafe:config:1.4.3) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class com.typesafe.config.ConfigBeanFactory found in modules config-1.4.3.jar -> config-1.4.3 (com.typesafe:config:1.4.3) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
...
Duplicate class dev.inmo.krontab.ExecutesKt found in modules krontab-debug.aar -> krontab-debug-runtime (dev.inmo:krontab-android-debug:2.3.0) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
...
Duplicate class io.ktor.client.HttpClient found in modules ktor-client-core-jvm-2.3.11.jar -> ktor-client-core-jvm-2.3.11 (io.ktor:ktor-client-core-jvm:2.3.11) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
...
Duplicate class kotlin.time.DurationKt found in modules kotlin-stdlib-1.9.23.jar -> kotlin-stdlib-1.9.23 (org.jetbrains.kotlin:kotlin-stdlib:1.9.23) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class kotlinx.coroutines.AbstractCoroutine found in modules kotlinx-coroutines-core-jvm-1.8.0.jar -> kotlinx-coroutines-core-jvm-1.8.0 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class kotlinx.datetime.Clock found in modules kotlinx-datetime-jvm-0.6.0.jar -> kotlinx-datetime-jvm-0.6.0 (org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.6.0) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class kotlinx.serialization.BinaryFormat found in modules kotlinx-serialization-core-jvm-1.6.3.jar -> kotlinx-serialization-core-jvm-1.6.3 (org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.6.3) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
Duplicate class org.jetbrains.exposed.dao.id.EntityID found in modules exposed-core-0.50.1.jar -> exposed-core-0.50.1 (org.jetbrains.exposed:exposed-core:0.50.1) and ktor-server-task-scheduling-jdbc-jvm-1.2.8.jar -> ktor-server-task-scheduling-jdbc-jvm-1.2.8 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.8)
@Szczypiorek44 Thanks for the info, i'll make a ticket for it, i think it's probably solvable with a simple Shade plugin config.
BTW, you're welcome to also contribute to the repo by creating a PR to fix this, as i'm currently the only maintainer, so help would be appreciated :)
@Szczypiorek44 I'm on it. Could you maybe please provide a minimal reproduction of the issue so i can validate it?
Sure. All I did was I've created new project in Android Studio, and in my build.gradle
I've added the ktor and your plugin:
implementation(libs.ktor.server.core) //I'm using toml
implementation(libs.ktor.server.callLogging)
implementation(libs.ktor.contentNegotiator)
implementation(libs.ktor.serialization.json)
implementation(libs.slf4j.android)
implementation("io.github.flaxoos:ktor-server-task-scheduling-jdbc:1.2.8")
That's it, it should be enough to recreate the issue. In case you need it here's my MainActivity:
class MainActivity : ComponentActivity() {
private val environment by lazy { createEnvironment() }
private val server by lazy { embeddedServer(Netty, environment) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
...
}
server.start()
}
private fun createEnvironment(): ApplicationEngineEnvironment =
applicationEngineEnvironment {
log = LoggerFactory.getLogger("ktor.application")
connector {
port = 8000
}
module {
module()
}
}
}
If you'll have a problem with recreating the issue let me know, then I'll give you access to my repo
@Szczypiorek44 Ok i'm removing the fat jar, this should solve the issue. there is a dependencyt on another lib of mine though, that is not yet hosted on maven central, and only on GH packages, which doesn't offer open read access, so i will need to host it on central which might take a few days. in the meantime i can add it to this repository
@Szczypiorek44 i just released a new version, 1.2.10, can you please try it and see if your issue is solved?
Hi @Flaxoos , sorry for the late reply.
So I've just updated dependency to:
implementation("io.github.flaxoos:ktor-server-task-scheduling-jdbc:1.2.10")
Unfortunately, issue still persists:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class _COROUTINE.ArtificialStackFrames found in the following modules: kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
Duplicate class _COROUTINE.CoroutineDebuggingKt found in the following modules: kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
Duplicate class _COROUTINE._BOUNDARY found in the following modules: kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
Duplicate class _COROUTINE._CREATION found in the following modules: kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
Duplicate class arrow.atomic.AtomicActual found in the following modules: arrow-atomic-jvm-1.2.0 (io.arrow-kt:arrow-atomic-jvm:1.2.0), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
...
Duplicate class io.github.flaxoos.ktor.server.plugins.taskscheduling.TaskConfiguration found in modules ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
...
Duplicate class io.ktor.client.HttpClient found in the following modules: ktor-client-core-jvm-2.3.2 (io.ktor:ktor-client-core-jvm:2.3.2), ktor-server-task-scheduling-core-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-core-jvm:1.2.10) and ktor-server-task-scheduling-jdbc-jvm-1.2.10 (io.github.flaxoos:ktor-server-task-scheduling-jdbc-jvm:1.2.10)
Hi Flaxoos,
I've encountered a small issue and would like to suggest a possible enhancement. Currently, the library bundles all its dependencies into the jar file. This approach, while self-contained, leads to a significant issue with Gradle in my project as it flags every single class as duplicated due to the bundled dependencies and refuses to compile.
Would it be possible to consider adding another build configuration that lets Gradle handle the transitive dependencies at build time instead? This change would help avoid the duplication issue and let us use this library in our project.
Thank you for considering this suggestion. Looking forward to your thoughts.