deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Java 25 compact source files shrink a Micronaut entry point to three lines

Java 25's compact source files (JEP 512) drop the class declaration and main method signature, and a dev.to walkthrough applies the feature to a Micronaut application and its Gradle config.

Java 25 compact source files shrink a Micronaut entry point to three lines

Java 25 removes the entry-point ceremony

Java 25 finalized compact source files through JEP 512, a language change that lets a runnable program be written without an explicit class declaration or the familiar public static void main signature. A walkthrough published on dev.to applies the feature to a Micronaut service and shows the application entry point shrinking to three lines.

What a compact source file is

As the dev.to post explains, the feature targets boilerplate that every Java program has historically required: a package declaration, a class wrapper and a formal main method. A compact source file keeps ordinary imports but replaces the rest with a bare top-level method. The compiler treats the file as an implicitly declared class whose name is taken from the file name, and a void main() method in that file becomes the program's entry point.

The Micronaut entry point, before and after

The conventional Micronaut bootstrap mirrors what most JVM web frameworks ask for — a small class whose main method hands control to the framework:

java package com.example;

import io.micronaut.runtime.Micronaut;

public class Application { public static void main(String[] args) { Micronaut.run(Application.class, args); } }

With a compact source file, the same behavior fits into a file named Application.java:

java import io.micronaut.runtime.Micronaut;

void main() { Micronaut.run(); }

The dev.to author points out what disappears: the package declaration, the class declaration and the full method signature, along with the need to pass the class reference to the framework explicitly.

Gradle configuration follows the file name

Because the compact file declares no package, the Gradle application block no longer refers to a fully qualified name and instead points at the bare class name:

application { mainClass = "Application" }

The post flags two practical requirements. First, the implicit class takes its name from the file, so the file name and the configured mainClass value must agree exactly — renaming one without the other leaves the build pointing at a class that no longer exists. Second, the file should sit at the root of src/main/java rather than nested under package-style directories. The Java compiler is lenient about directory layout, the post notes, but IDEs and incremental compilation behave more predictably when the layout matches convention.

Why it matters

The observation underlying the walkthrough is that project structure is essentially identical across Spring, Micronaut, Quarkus and Helidon, so the simplification is broadly applicable rather than Micronaut-specific. The entry point of a framework application carries no business logic; it is arguably the least interesting code in the project, and Java 25 finally lets it stop occupying space. That lowers friction for small services, experiments and teaching examples, and gives newcomers a cleaner first contact with the language.

There are trade-offs worth weighing. The file name and the build configuration are now coupled in a way they were not before, and directory conventions still matter to tooling even when the compiler does not enforce them. Teams that need an explicit class or package for other reasons, or those not yet on Java 25, gain nothing immediately. Even so, this is a meaningful quality-of-life improvement: Java's smallest programs can now look as small as they actually are.

  • #java
  • #micronaut
  • #gradle
  • #jvm

Related posts