Skip to main content

webforJ build plugin 26.01

Open in ChatGPT

The webforJ build plugin runs webforJ's build time work as part of your Maven or Gradle build. You add it once, and it binds its goals to the phases you already run, with no separate frontend project to keep in sync. It drives the frontend bundler, compiling the frontend, running the frontend tests, serving the development watch, and attaching a hotswap tool to the app it starts.

Adding the plugin

A webforJ project created from an archetype already has the plugin. To add it to an existing project:

Declaring the plugin with <extensions>true</extensions> binds its goals to the build with no execution blocks to write:

pom.xml
<plugin>
<groupId>com.webforj</groupId>
<artifactId>webforj-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>

Goals and tasks

Three goals bind to phases you already run, so a normal mvn package or ./gradlew build produces an app with its frontend compiled in, and the test phase runs the frontend tests alongside the Java tests. The watch is the one you start by hand during development:

Maven goalGradle taskRunsWhat it does
bundlewebforjBundleprepare-package, before every jar and warCompiles the frontend for the packaged app
testwebforjTestwith the test phaseRuns the frontend tests
cleanwebforjCleanFrontendwith the clean phaseRemoves the generated frontend
watchwebforjWatchby hand, alongside the appRebuilds on change during development
push-keyswebforjPushKeysby hand, once per deploymentGenerates the key pair for push notifications and prints the configuration lines

Start the watch as the goal before the one that runs the app, mvn compile webforj:watch spring-boot:run for example. An archetype project sets this as the default goal, so mvn alone starts everything. Its reload behavior is covered in Frontend watch.

Skip the frontend tests together with the Java tests, -DskipTests or -Dmaven.test.skip with Maven and -PskipTests with Gradle.

Options

Set options as Maven <configuration> elements, or as Gradle webforj { } extension values. Every Maven option except plugins and hotswap also accepts a -D property on the command line. The two build tools mirror each other:

Maven elementMaven propertyGradleDefaultPurpose
bunVersionwebforj.bundler.versionbunVersionmanagedPin the Bun version for reproducible builds
bunPathwebforj.bundler.pathbunPathdownloadUse an existing Bun binary instead of downloading
cacheDirwebforj.bundler.cacheDircacheDir${user.home}/.webforj/bunWhere managed Bun binaries are cached
sourceRootwebforj.bundler.sourceRootsourceRootsrc/main/frontendWhere the frontend entry sources live
workDirwebforj.bundler.workDirworkDirtarget/bundleWhere the plugin writes its generated build files
pluginspluginsTurn an extension on or off by id, such as webforj-tailwind
excludePackageswebforj.bundler.excludePackagesexcludePackagesPackage prefixes to skip during the annotation scan
eagerwebforj.bundler.eagereagerfalseLoad the whole frontend at app start instead of per view, see Eager bundle
testArgswebforj.bundler.testArgstestArgsExtra arguments passed to the frontend test runner
hotswaphotswapAttach a class update tool to the app the build starts, see Hotswap

For example, to pin the Bun version and turn on Tailwind:

pom.xml
<plugin>
<groupId>com.webforj</groupId>
<artifactId>webforj-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<bunVersion>1.3.0</bunVersion>
<plugins>
<webforj-tailwind>true</webforj-tailwind>
</plugins>
</configuration>
</plugin>