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

INCLUDE DependsOn with class packages in different namespace #334

Open
HoffiMuc opened this issue Nov 29, 2021 · 1 comment
Open

INCLUDE DependsOn with class packages in different namespace #334

HoffiMuc opened this issue Nov 29, 2021 · 1 comment

Comments

@HoffiMuc
Copy link

HoffiMuc commented Nov 29, 2021

In my case, I have my main in package x.y
and want to INCLUDE / DependsOn a file in package x.a as well as in package x.y.z

@file:DependOn(...)

@file:Include("../helpers/CamelCase.kt")
@file:Include("./mappings/Jira.kt")

@file:EntryPoint("com.hoffi.something.AppKt")

package com.hoffi.something

import DependsOn
import EntryPoint
import Include
import com.hoffi.something.mappings.Histories

fun main(args: Array<String>) {
    App().main(args)
}

class App : CliktCommand() {
    override fun run() {
        ...
    }
}

doesn't find the class which is one of the defined classes in ./mappings/Jira.kt

package com.hoffi.something.mappings

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.time.Instant

...
@SerialName("histories")
@Serializable data class Histories(
    val author: Author,
    @Serializable(InstantSerializer::class) val created: Instant,
    val id: String,
    val items: MutableList<Items>,
)
...

gives me:

/tmp/tmp17398417963705588090.tmp/scriptlet.248cdc652452029b.kt:18:18: error: unresolved reference: something
import com.hoffi.something.mappings.Histories
                 ^

btw: ... it took me a long time to really understand your comment you added in ee7748e

@holgerbrandl
Copy link
Collaborator

I guess this use case is not supported, and it's unlikely that this will ever work. @file:Include works by literally rewriting your script code prior to compilation to include the include-file at the given location. kscript tries to be a bit more clever, to at least sort imports to the top of the merged script. But it can't resolve the conflict you've created in your example where a single source file has 2 package statements. This is not legit according to the kotlin language specification.

Does this answer help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants