question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using kotlin data classes in jte templates have issues compiling java sourceset.

See original GitHub issue

I have the following project setup.

└── src
    ├── main
    │   ├── java
    │   │   └── dev
    │   │       └── ...
    │   ├── kotlin
    │   │   └── dev
    │   │           ├── jte
    │   │           │   └── RenderJte.kt
    │   └── templates
    │       └── jte
    │           └── hello.jte

Jte template (hello.jte) uses a kotlin data classes

@import dev.suresh.jte.Config
@import java.time.LocalDateTime

@param Config config
Hello ${config.getLanguage()} - ${config.getVersion()}
Rendered By Jte on ${LocalDateTime.now().toString()}
import gg.jte.*
import gg.jte.output.*

data class Config(val language: String, val version: String)

class RenderJte {
    fun run() {
        val tmplEngine = TemplateEngine.createPrecompiled(ContentType.Plain)
        val output = StringOutput()
        tmplEngine.render("hello.jte", Config("Kotlin", App.KOTLIN_VERSION), output)
        println(output)
    }
}

Kotlin Gradle script setup is,


plugins {
   java
   application
   kotlin("jvm") version "1.4.3"
   id("gg.jte.gradle") version "1.7.0"
}

// Add the generated templates to source set.
sourceSets {
    main {
        java.srcDirs(
            tasks.generateJte.get().targetDirectory
        )
    }
}

tasks {

    withType<JavaCompile>().configureEach {
         ....
        dependsOn(generateJte)
    }
    
     // Jte templates
    generateJte {
        sourceDirectory = Path.of("src", "main", "templates", "jte")
        contentType = ContentType.Plain
    }
 }

The issue here is, once we add generateJte dependency on javaCompile task, it’s missing java classes (src/main/java) classes in the final jar.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
casidcommented, Feb 25, 2021

@sureshg I just published version 1.7.0.1 of the gradle plugin containing this hotifx.

https://plugins.gradle.org/plugin/gg.jte.gradle

2reactions
casidcommented, Feb 24, 2021

Sweet! Thanks for testing it and sharing your code sample!

I’ve updated the gradle kts documentation 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java module depending on Kotlin module unable to compile
I have been running into some strange issues when depending on a gradle module that uses Kotlin. I have setup a small demo...
Read more >
Confusing data class copy with private constructor
When the primary constructor of data classes is private, copy() probably should be private ... Just released a compiler plugin that helps with...
Read more >
Generate a Java file and include it in the sourceSet for ...
Assuming that I might have something like src/main/java/foo/bar.java … ... file from a template, then include it as part of the source set...
Read more >
Known issues with Android Studio and Android Gradle Plugin
lifecycle:lifecycle-runtime in your module. If you're seeing java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.
Read more >
Rendering jte templates in Javalin
Introductionjte is a modern, type-safe template engine, that glues HTML and Java with as little extra syntax as possible.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found