Giter Club home page Giter Club logo

Comments (9)

casid avatar casid commented on August 17, 2024 2

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

I've updated the gradle kts documentation 👍

from jte.

casid avatar casid commented on August 17, 2024 2

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

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

from jte.

sureshg avatar sureshg commented on August 17, 2024 1

I think you should use source() method instead of include


    /**
     * Adds some source to this task. The given source objects will be evaluated as per {@link org.gradle.api.Project#files(Object...)}.
     *
     * @param sources The source to add
     * @return this
     */
    public SourceTask source(Object... sources) {
        sourceFiles.from(sources);
        return this;
    }

from jte.

sureshg avatar sureshg commented on August 17, 2024 1

@casid Awesome...that worked! Tested on a sample project with a mix of Java and Kotlin and templates are generating fine for both Java 16 records and Kotlin data classes as params. Really nice.

package dev.suresh.jte;

import java.util.Objects;

public record Config(String language, String version) {

  public Config() {
    this(null, null);
  }

  public Config {
    language = Objects.requireNonNullElse(language, "Java");
    version = Objects.requireNonNullElse(version, System.getProperty("java.version"));
  }
}
package dev.suresh.jte

import App
import gg.jte.*
import gg.jte.output.*

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

class RenderJte {
    fun run() {
        val tmplEngine = TemplateEngine.createPrecompiled(ContentType.Plain)
        val output = StringOutput()
        val params = mapOf(
            "config" to Config(),
            "ktConfig" to KtConfig("Kotlin", App.KOTLIN_VERSION),
        )
        tmplEngine.render("hello.jte", params, output)
        println(output)
    }
}
@import dev.suresh.jte.Config
@import dev.suresh.jte.KtConfig
@import java.time.LocalDateTime

@param Config config
@param KtConfig ktConfig

Hello ${config.language()} - ${config.version()}
Hello ${ktConfig.getLanguage()} - ${ktConfig.getVersion()}
Rendered By Jte on ${LocalDateTime.now().toString()}

All I had to do is configuring the java sourceset in Gradle kts file

sourceSets {
   main {
         java.srcDirs(tasks.generateJte.get().targetDirectory)
    }
}

// Jte templates
tasks.generateJte {
     sourceDirectory = Path.of("src", "main", "templates", "jte")
      contentType = ContentType.Plain
}
    
tasks.withType<KotlinCompile>().configureEach {
        kotlinOptions {
            verbose = true
            jvmTarget = kotlinJvmTarget
            useIR = true
        }
        
       // Generate Jte templates.
        dependsOn(generateJte)
}

from jte.

sureshg avatar sureshg commented on August 17, 2024 1

@casid Thanks! What is your release schedule? When i can expect the latest version on https://plugins.gradle.org/ ?

from jte.

casid avatar casid commented on August 17, 2024

@sureshg I'm not sure if this is causing this problem, but generateJte cleans the targetDirectory before sources are generated.

However, that directory is by default Paths.get(getProject().getBuildDir().getAbsolutePath(), "generated-sources", "jte");, which shouldn't contain any other Java classes.

If that's not the problem, maybe this

sourceSets {
    main {
        java.srcDirs(
            tasks.generateJte.get().targetDirectory
        )
    }
}

doesn't add to srcDirs, but replaces them? I tried to find a kotlin version of sourceSets.main.java.srcDirs += tasks.generateJte.targetDirectory for the documentation, but failed miserably.

from jte.

casid avatar casid commented on August 17, 2024

@sureshg did you have any luck resolving this?

from jte.

sureshg avatar sureshg commented on August 17, 2024

@casid I have been playing around with different Gradle kts config for a project contain both Java and Kotlin. One thing i noticed is, after applying the jte plugin, the whole source becomes empty (for both java and kotlin)

> Task :generateJte
Caching disabled for task ':generateJte' because:
  Caching has not been enabled for the task
Task ':generateJte' is not up-to-date because:
  Output property 'targetDirectory' file /Users/sgopal1/code/openjdk-playground/build/generated-sources/jte has been removed.
  Output property 'targetDirectory' file /Users/sgopal1/code/openjdk-playground/build/generated-sources/jte/gg has been removed.
  Output property 'targetDirectory' file /Users/sgopal1/code/openjdk-playground/build/generated-sources/jte/gg/jte has been removed.
Generating jte templates found in src/main/templates/jte
Successfully generated 1 jte file in 0s to /Users/sgopal1/code/openjdk-playground/build/generated-sources/jte
:generateJte (Thread[Execution worker for ':',5,main]) completed. Took 0.042 secs.
:kaptGenerateStubsKotlin (Thread[Execution worker for ':',5,main]) started.

.....

> Task :kaptKotlin
Build cache key for task ':kaptKotlin' is ac418f2d14f73272ee57fa843739dddc
Task ':kaptKotlin' is not up-to-date because:
  Output property 'classesDir$kotlin_gradle_plugin' file /Users/sgopal1/code/openjdk-playground/build/tmp/kapt3/classes/main has been removed.
  Output property 'destinationDir' file /Users/sgopal1/code/openjdk-playground/build/generated/source/kapt/main has been removed.
  Output property 'kotlinSourcesDestinationDir' file /Users/sgopal1/code/openjdk-playground/build/generated/source/kaptKotlin/main has been removed.
The input changes require a full rebuild for incremental task ':kaptKotlin'.
Running kapt annotation processing using the Gradle Worker API
Kapt worker classpath: []
Stored cache entry for task ':kaptKotlin' with cache key ac418f2d14f73272ee57fa843739dddc
:kaptKotlin (Thread[Execution worker for ':',5,main]) completed. Took 1.172 secs.
:compileKotlin (Thread[Execution worker for ':',5,main]) started.

> Task :compileKotlin NO-SOURCE
Skipping task ':compileKotlin' as it has no source files and no previous output files.
:compileKotlin (Thread[Execution worker for ':',5,main]) completed. Took 0.001 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava NO-SOURCE
Skipping task ':compileJava' as it has no source files and no previous output files.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.001 secs.
:classes (Thread[Execution worker for ':',5,main]) started.

Here you can see the tasks are skipped because of NO-SOURCE. When I checked the plugin source, I can see you are adding an ANT style include pattern for all the source tasks here -

getProject().getTasks().withType(SourceTask.class).all(sourceTask -> sourceTask.include(targetDirectory.toAbsolutePath().toString()));

Which is basically the source set for all these tasks in my case

compileJava
compileKotlin
compileTestJava
compileTestKotlin
javadoc
kaptGenerateStubsKotlin
kaptGenerateStubsTestKotlin

Is this causing the issue here? As I mentioned, things are working fine after removing the jte plugin.

By the way here is the difference in task order after and before applying the jte plugin.
Screen Shot 2021-02-23 at 10 20 41 PM

from jte.

casid avatar casid commented on August 17, 2024

Hey @sureshg, thank you so much for your in-depth investigation! That's very, very helpful. I have to admit - I'm quite a Gradle Noob ^^.

I removed the include alltogether, it had no effect in my test project.

Could you give this a try in your test project? I think you would need to:

  • Check out the jte repository's master branch
  • Run mvn clean install
  • Run gradle publishToMavenLocal in jte-gradle-plugin

You would need to temporarily set the plugin version to 1.8.0-SNAPSHOT and add the mavenLocal repo to your project, so that the snapshot plugin can be found.

repositories {
  mavenCentral()
  mavenLocal()
}

from jte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.