I swear I read something that you can include a gr...
# gradle
e
I swear I read something that you can include a groovy block inside a kts build script, but can’t find it now. Any help?
s
All the possible approaches for interoperability should be listed here: https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:interoperability
👍 1
v
You can kind-of and there are different things you might remember. Why do you actually need it?
e
I’m writing a gradle plugin to reduce all the boilerplate in our services’s build scripts. That includes applying a plugin whose extension class is marked as
internal
so i can’t get it using something like:
Copy code
extensions.getByType<ApolloExtension>().apply { ... }
I can get it like this:
Copy code
extensions.getByName("apollo").apply { ... }
But then I have no typing wrt the the extension and can’t modify the configuration.
Maybe
extensions.getByName("apollo").withGroovyBuilder { ... }
?
v
That could work, yes. But the question is whether you really should modify that extension if it is not designed to be modified, or talk to the plugin author to broaden the scope. 🙂
e
It is just configuration data that’s nearly exactly the same between all the services. like
Copy code
extensions.getByName("apollo").withGroovyBuilder {
    setProperty("service.name", "test")
    setProperty("service.packageNamesFromFilePaths", "com.company.service.graphql.client")
    setProperty("srcDir", "src/test/graphql")
    setProperty("customTypeMapping", mapOf(
        "DateTime" to "java.time.Instant",
        "UUID" to "java.util.UUID"
    ))
}
v
Still don't know what should be internal and why you think you need Groovy
message has been deleted
e
right… that’s in a project using apollo, not in a plugin configuring apollo for use in projects
v
Shouldn't make much difference
e
yeah, but it won’t resolve
s
Maybe you just need to add a dependency?
e
i did
Copy code
implementation("com.apollographql.apollo3:apollo-gradle-plugin:$apolloVersionV3")
the class is in that ^ jar
message has been deleted
My guess is that they are using modules to make it internal
v
But that would be bad and also why should they? And whouldn't it also break for the kts then?
e
i honestly have no idea…
v
grep -ao '[a-zA-Z0-9_$]\+' *.kotlin_module | grep ApolloExtension
gives no result
e
those files appear to be bytecode
v
But the have class names in them
Copy code
grep -ao '[a-zA-Z0-9_$.]\+' apollo-gradle-plugin.kotlin_module
X
$com.apollographql.apollo3.gradle.api
AndroidProjectKt
JavaProjectKt
KotlinProjectKt
com.apollographql.apollo3.gradle.internal
AndroidAndKotlinPluginFacadeKt
AndroidPluginFacadeKt
KotlinPluginFacadeKt
RegisterOperationsKt
And actually, even though the IDE is unhappy,
Copy code
target.configure<ApolloExtension> {
    service("test") {
        packageNamesFromFilePaths("com.company.service.graphql.client")
    }
    srcDir("src/test/graphql")
    customTypeMapping.putAll(
        mapOf(
            "DateTime" to "java.time.Instant",
            "UUID" to "java.util.UUID"
        )
    )
}
works perfectly fine
Maybe more an IDE Kotlin plugin bug
e
if that’s the case… so much time wasted. let me try
sigh… yeah, my tests all pass
v
Also afair you cannot directly influence the content of those module files. They are just a compilation artifact, defining which classes belong to the same module for things that actually are internal
e
thanks for your help. not sure if i should put in a kotlin plugin youtrack for this
v
You probably should
Working code is shown red
👍 1
I'll even vote for it if you share the link
e
🙂
took a while to create the minimal project and get ssh setup again since my laptop crashed a few weeks ago https://youtrack.jetbrains.com/issue/KTIJ-21336
👌 1