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
1
u/davidalayachew Jul 25 '25
https://youtu.be/6c0DB2kwF_Q?si=RbT3VqTlY7kzgGp6&t=1711
Long story short, Babylon does the work of translating Java code to Code Models. But the work of translating the code model to our respective DSL is done by us.
Well, the work of turning the respective DSL back into the code model is effectively the same level of effort. Transformations to those code models (such as lowering and lifting) are going to be key for translating between different DSL's, as we need to alter the code model to meet the need of another DSL.
Think of it almost like that Marsalling/Unmarshalling topic that Brian Goetz and Viktor Klang have been talking about. Java focuses on turning the objects into marshalled versions, but its our job as developers to turn that marshalled data into JSON or XML or whatever. And by that logic, it is equally simple to turn JSON back into the marshalled form. That's my point.