Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Dependency Management Enhancement in ktor-server-task-scheduling #30

Closed
tb-kpabla opened this issue Apr 25, 2024 · 12 comments · Fixed by #61
Closed

Request for Dependency Management Enhancement in ktor-server-task-scheduling #30

tb-kpabla opened this issue Apr 25, 2024 · 12 comments · Fixed by #61
Assignees
Labels
bug Something isn't working

Comments

@tb-kpabla
Copy link

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.

@Szczypiorek44
Copy link

Szczypiorek44 commented Apr 26, 2024

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.

@Flaxoos
Copy link
Owner

Flaxoos commented May 30, 2024

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?

@Szczypiorek44
Copy link

Szczypiorek44 commented Jun 3, 2024

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)

@Flaxoos
Copy link
Owner

Flaxoos commented Jun 3, 2024

@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 :)

@Flaxoos Flaxoos added the bug Something isn't working label Jun 3, 2024
@Flaxoos Flaxoos self-assigned this Jun 20, 2024
@Flaxoos
Copy link
Owner

Flaxoos commented Jun 20, 2024

@Szczypiorek44 I'm on it. Could you maybe please provide a minimal reproduction of the issue so i can validate it?

@Szczypiorek44
Copy link

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()
            }
        }
}

@Szczypiorek44
Copy link

If you'll have a problem with recreating the issue let me know, then I'll give you access to my repo

@Flaxoos
Copy link
Owner

Flaxoos commented Jun 20, 2024

@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

Flaxoos added a commit that referenced this issue Jun 21, 2024
Flaxoos added a commit that referenced this issue Jun 21, 2024
- removed shadow usage
- using published redis client
Flaxoos added a commit that referenced this issue Jun 21, 2024
- removed redis client project form settings
@Flaxoos Flaxoos reopened this Jun 22, 2024
@Flaxoos
Copy link
Owner

Flaxoos commented Jun 22, 2024

@Szczypiorek44 i just released a new version, 1.2.10, can you please try it and see if your issue is solved?

@Szczypiorek44
Copy link

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)
   

@Flaxoos Flaxoos mentioned this issue Oct 16, 2024
@Flaxoos Flaxoos linked a pull request Oct 16, 2024 that will close this issue
@Flaxoos
Copy link
Owner

Flaxoos commented Oct 16, 2024

@Szczypiorek44 Fix is in #61

@Szczypiorek44
Copy link

Hi @Flaxoos
Great news! I'll try to test it soon. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants