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, and serving the development watch.

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

The plugin binds four goals, each to a phase you already run, so a normal mvn package or gradle build produces an app with its frontend compiled in, and mvn test runs the frontend tests alongside the Java tests.

Maven goalGradle taskPhaseWhat it does
bundlewebforjBundleprepare-packageCompiles the frontend for production
testwebforjTesttestRuns the frontend tests
cleanwebforjCleanFrontendcleanRemoves the generated frontend
watchwebforjWatchrun by handRebuilds on change during development

The watch goal is the one you run by hand during development, alongside the app. Its reload behavior is covered in Frontend watch.

Options

Set options as Maven <configuration> (or -D properties on the command line), and as Gradle webforj { } extension values. The two build tools mirror each other.

OptionMaven propertyGradleDefaultPurpose
Bun versionwebforj.bundler.versionbunVersionmanagedPin the Bun version for reproducible builds
Bun binarywebforj.bundler.pathbunPathdownloadUse an existing Bun binary instead of downloading
Cache directorywebforj.bundler.cacheDircacheDir${user.home}/.webforj/bunWhere managed Bun binaries are cached
Source rootwebforj.bundler.sourceRootsourceRootsrc/main/frontendWhere the frontend entry sources live
Work directorywebforj.bundler.workDirworkDirtarget/bundleWhere the plugin writes its generated build files
ExtensionspluginspluginsTurn an extension on or off by id, such as webforj-tailwind
Exclude packageswebforj.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
Test argumentswebforj.bundler.testArgstestArgsExtra arguments passed to the frontend test runner
Skip testsskipTests, maven.test.skipfalseSkip the frontend tests

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>
<version>1.3.0</version>
<plugins>
<webforj-tailwind>true</webforj-tailwind>
</plugins>
</configuration>
</plugin>