-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Labels
ideasSome idea/suggestion around jbang behavior/feature setSome idea/suggestion around jbang behavior/feature set
Description
I have been working with Python's PEP 723 inline script metadata format and have come to like it a lot. It is simply a TOML data structure encoded in comments. Adapted to JBang it would allow the JBang configuration for Java / Kotlin / Groovy to be specified as shown in the example below:
///usr/bin/env jbang "$0" "$@" ; exit $?
// ||| jbang
// requires-java = ">=21"
// dependencies = [
// "org.springframework.boot:spring-boot-starter-web:3.4.4",
// ]
// [java]
// runtime-options = "-server -Xms2g -Xmx2g -XX:+UseZGC -XX:+ZGenerational"
// |||
import static java.lang.System.*;
public class test {
public static void main(String... args) {
out.println("Hello World");
}
}What are the benefits of this approach?
- Standardized configuration format (TOML)
- Easier to parse the configuration data. The Toml block is extracted and then processed by a Toml library (org.tomlj:tomlj:1.1.1).
- Extensible configuration format, new options can easily be added.
- Additional (optional) support could even be provided to externalize the JBang configuration to a file which could then be included in the JBang scriipt. But this will also make it slighly harder to determine if a script should be recompiled (the source did not change, but the config did).
///usr/bin/env jbang "$0" "$@" ; exit $?
// ||| jbang
// jbang-config = "config.toml"
// |||
import static java.lang.System.*;
public class test {
public static void main(String... args) {
out.println("Hello World");
}
}- By sharing a configuration file, several related scripts could use the same runtime options that are specified in one place.
- Editing and syntax highlighting support of TOML configuration files via extensions for VSCode, Intellij, etc.
- A
--configoption could be added to JBang to override the configuration of a JBang script to use a different config.toml file. - A
--configoption would also allow files that do not contain any JBang comments to be provided with configuration data at runtime (if required).
// Run with JBang as: jbang --config config.toml run test.java
import static java.lang.System.*;
public class test {
public static void main(String... args) {
out.println("Hello World");
}
}- Migration support could be provided to rewrite a JBang script file and group the JBang //? config options into a single TOML config comment block or to write the config to a TOML file.
- If a external config file is used for the JBang config options, then script processing time would be reduced because the script does not have to be scanned for information.
Metadata
Metadata
Assignees
Labels
ideasSome idea/suggestion around jbang behavior/feature setSome idea/suggestion around jbang behavior/feature set
