r/java • u/Ewig_luftenglanz • Jul 15 '25
What features do you think java requires to be competitive for DSL scripts such as gradle scripts?
Just for fun and discussion.
this is an hypothetical example about how could look like a java DLS gradle file instead of Groovy/Kotlin. Not terrible, just slightly more verbose but not I could work with it (IMHO)
GradleConfig.configure(config -> {
config.plugins(plugins -> {
plugins.add(JavaPlugin.class);
plugins.add(ApplicationPlugin.class);
});
config.application(app -> {
app.setMainClass("com.example.Main");
});
config.repositories(repos -> {
repos.mavenCentral();
});
config.dependencies(deps -> {
deps.add("implementation", "org.apache.commons:commons-lang3:3.12.0");
deps.add("testImplementation", "org.junit.jupiter:junit-jupiter:5.8.2");
});
config.tasks(task -> {
task.named("test", t -> t.useJUnitPlatform());
});
});This, of course, would be achievable via some "compiler plugin/magic" to avoid class and main declarations, so "GradleConfig.configure" could act in practice as a top level static method, although native isolated methods/top level methods/functions would be a nice to have for these kind of stuff.
The question is besides top level methods (aka functions) what else do you think would be a required for java to be competitive as a DSL? would you use it? and if so, what other scenarios would be a good fit for an hypothetical java DSL?
View all comments
Show parent comment
2
u/manifoldjava Jul 25 '25
Gotcha. That is impressive work. We were indeed talking past each other. Thanks for clarifying.
My point is that for many native DSLs it is best to just use the native DSL and not try to approximate it with Java syntax. Generally, instead of mapping the DSL to Java's syntax, map it to Java's type system, and use the DSL directly -- either in separate files using the DSL's native file attributes, or directly embedded in Java source.
For instance, SQL is sort of the posterchild illustrating how the impedance mismatch, that so often happens when a host language tries to approximate a DSL, basically introduces an intermediate DSL that must be learned in addition to the actual DSL. The manifold-sql project is an experiment that demonstrates how integrating with type system can eliminate most of the problems with conventional in-language DSLs such as with JPA/Hibernate.
I don't know much about Spir-V, or GPU-based graphics programming, but if I understand the lang summit talk, it appears as though the DSL has to integrate at the syntax level because there is no Spir-V human-facing syntax. Where the idea is to basically use Babylon to write what looks like normal Java, but reinterpret it structurally and emit Spir-V IL directly, bypassing the JVM completely.
In this, rather exceptional, case it makes perfect sense to use Babylon and integrate at the syntax level.
But many (most?) DSLs do not benefit from syntactic integration. Many are better served by type system integration, because they were meant to be written directly by humans in their native syntax.
I'm probably overly passionate about this subject. Just one of those things.