Comments (9)
Sweet! Thanks for testing it and sharing your code sample!
I've updated the gradle kts documentation 👍
from jte.
@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.
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.
@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.
@casid Thanks! What is your release schedule? When i can expect the latest version on https://plugins.gradle.org/ ?
from jte.
@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.
@sureshg did you have any luck resolving this?
from jte.
@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 -
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.
from jte.
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)
- For Loops won't compile for Kotlin HOT 2
- internationalization with MessageFormat HOT 6
- HTML Comments Inside Content Blocks Cause Compilation Failure in gg.jte.gradle v3.1.7+ HOT 2
- Allow expressions in HTML attribute names for certain types HOT 9
- Spring Boot integration and binary rendering HOT 6
- ${"\\"} Causes "Unexpected end of template expression" HOT 1
- Pass dynamic HTML Content to template HOT 2
- Support JTE project HOT 2
- Failed to compile with module-info.java HOT 2
- Support for read-only filesystem HOT 1
- template define with generic type HOT 1
- Generic template HOT 3
- Html Template Output HOT 2
- Add kotlin and kte documentation HOT 1
- String input instead of file input HOT 6
- Provide jte-jsp-converter for Jakarta HOT 1
- Comments break JTE HOT 5
- intellij "Cannot resolve MVC view" HOT 4
- Unable to handle model properties that contain dots (`.`) HOT 3
- KTE runtime dependencies HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jte.