Skip to content

Cannot use customTemplates #1244

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

Closed
ABashkirtseva opened this issue Jun 7, 2023 · 2 comments
Closed

Cannot use customTemplates #1244

ABashkirtseva opened this issue Jun 7, 2023 · 2 comments
Labels
question Further information is requested

Comments

@ABashkirtseva
Copy link

I've create custom templates for Types and Inputs but when I specify them in gradle, I have an error from FreeMaker that a template is not found:

My gradle task:

tasks.named<io.github.kobylynskyi.graphql.codegen.gradle.GraphQLCodegenGradleTask>("graphqlCodegen") {
    graphqlSchemaPaths = listOf("$projectDir/src/main/resources/graphql/schema.graphql")
    outputDir = File("$buildDir/generated")
    apiPackageName = "my.graphql.api"
    modelPackageName = "my.graphql.model"

    // TODO: If we generate Kotlin classes, we get better builders and null-safety.
    generatedLanguage = GeneratedLanguage.KOTLIN
    isGenerateNoArgsConstructorOnly = true
    customTemplates = mutableMapOf(
        FreeMarkerTemplateType.TYPE.name to "src/main/resources/graphql/type.ftl",
        FreeMarkerTemplateType.PARAMETRIZED_INPUT.name to "src/main/resources/graphql/input.ftl",
    )
}

The error that I've got:

Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "src/main/resources/graphql/type.ftl".
The name was interpreted by this TemplateLoader: MultiTemplateLoader(loader1 = ClassTemplateLoader(classLoader="InstrumentingVisitableURLClassLoader(ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:]:buildSrc[:]:root-project[:](export)})", basePackagePath=""), loader2 = FileTemplateLoader(baseDir="/Users/admin/.gradle/daemon/8.1.1", canonicalBasePath="/Users/admin/.gradle/daemon/8.1.1/")).
        at freemarker.template.Configuration.getTemplate(Configuration.java:2957)
        at freemarker.template.Configuration.getTemplate(Configuration.java:2759)
        at com.kobylynskyi.graphql.codegen.generators.FreeMarkerTemplatesRegistry.getCustomTemplates(FreeMarkerTemplatesRegistry.java:84)

And I definitely have them:
image

I was trying to change path from "src/main/resources/graphql/type.ftl" to "$projectDir/src/main/resources/graphql/type.ftl". But still have the same error.

What am I doing wrong?

@esfomeado
Copy link
Contributor

Use the newest version and set the path using customTemplatesRoot

@jxnu-liguobin jxnu-liguobin added the question Further information is requested label Aug 6, 2023
@ABashkirtseva
Copy link
Author

That works, thanks!

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

No branches or pull requests

3 participants