Why did `serve` display an ugly site while `publishSite` was perfect
Published on 22 April 2026
You know that moment when your site locally looks like nothing, but once it’s deployed online everything is perfect? That’s what happened to me with my Gradle JBake plugin. The task`serve`displayed square buttons, dark text on a black background, and a strangely missing CSS. Yet`publishSite`generated the same site, flawless. The culprit was neither the CSS, nor the browser, nor the cache. It was a line of Kotlin code — and a bad habit with command‑line arguments.
The scene: four screenshots, two renders
It was after a system crash. I had taken four screenshots to compare the local rendering../gradlew serve`on`localhost:8820) with the online rendering (`publishSite`on GitHub Pages). Two screenshots per page: the top and the bottom.
Local rendering
Top of page— The Project and Template buttons aresmall, rectangular, in the standard colors (blue and green). The Start Writing card has asolid black background, without frame.
Footer— The subtitle "Latest articles and resources" isalmost unreadable, too dark on black background. The dates under the blog images ("17 October 2013", etc.) areabsentees.
Rendered online
Top of page— The same buttons arelarge, oval, flashy neon green, text in uppercase. The card has awhite rounded frame with drop shadow.
Footer— The subtitle isreadable. The dates arevisible. The article cards haverounded cornersand the titles arein bold.
First reflex: the theme. I use a dynamic theme system (light, dark, high-contrast) based on`localStorage`. Maybe the local store was triggering a high‑contrast theme? No. I had already writtenhttps://cheroliv.com/blog/2025/0098_preloading_css_variable_post.html[a full article on theme preloading], I know how it works. And then, even in high-contrast mode, the CSS structure (oval buttons, shadows) was supposed to be there. It wasn’t.
Second reflex: the browser cache. No, I had done the test with clean profiles. The diff persisted.
Third reflex:`serve`did not serve the same files as`publishSite`.
The diagnosis: serve was not pointing to the correct folder
My Gradle plugin`bakery`has two main tasks:
-
bake: generates the static site in`build/bake/` -
serve: launch a local web server -
publishSite: push`build/bake/`to GitHub Pages
The divergence could only come from`serve`. Si publishSite`published the correct content, it’s that`build/bake/`was good. If`serve`displayed something else, it’s that it wasn’t serving`build/bake/.
Let’s look at the code. In`SiteManager.kt`, the task`serve`is defined as follows:
tasks.register("serve", JavaExec::class.java) { task ->
task.apply {
mainClass.set("org.jbake.launcher.Main")
classpath = jbakeRuntime
environment("GEM_PATH", jbakeRuntime.asPath)
jvmArgs(/* ... */)
args = listOf(
"-b", file(site.bake.srcPath).absolutePath,
"-s", layout.buildDirectory.get()
.asFile.resolve(site.bake.destDirPath)
.absolutePath
)
}
}
org.jbake.launcher.Main`is the entry point of the JBake 2.7.0 CLI. The idea: pass-b`for the source folder and`-s`for the destination folder, then launch the server mode. Except that…
The root cause: JBake CLI does not work like that
JBake 2.7.0 expectspositional argumentsfor source and destination, then optional flags. The signature is:
jbake <source> <destination> [options]
But in my code, I wrote:
args = listOf("-b", "/path/to/site", "-s", "/path/to/build/bake")
JBake interpreted this as:
-
-b→ parse the "bake" flag (boolean), consumed -
/path/to/site→ becomes positional argument 1 (source) -
-s→ parse the "serve" flag (boolean), server startedimmediately -
/path/to/build/bake→ becomes an orphan argument, ignored or misinterpreted
Result: JBake was taking`/path/to/site`as a source,did not take the destination into accountprovided (build/bake), and used its default directory (often`./output`or a temporary copy). The file`css/styles.css`the build was therefore overwritten or ignored, and it’s an old default CSS (without custom variables, without rounded corners, without shadows) that was served.
In comparison,bake et publishSite`use theofficial Gradle JBake plugin (`jbake-gradle-plugin) who writes neatly in`build/bake/`via the Gradle API. They don’t go through the CLI.
The solution: positional arguments, not flags
The fix is trivial — once you know. You just need to pass source and destination as positional arguments, then`-s`last:
args = listOf(
file(site.bake.srcPath).absolutePath,
layout.buildDirectory.get()
.asFile.resolve(site.bake.destDirPath)
.absolutePath,
"-s"
)
That’s all. Three lines changed, bug fixed.
After local publishing of the plugin (publishToMavenLocal), un `./gradlew serve`run JBake with the correct syntax:
jbake /home/user/project/site /home/user/project/build/bake -s
And this time, the Jetty server integrated into JBake does serve the content of`build/bake/`— identical to what is published online.
@startuml
!define RECTANGLE class
package "AVANT (bug)" {
RECTANGLE JBakeCLI1 {
+ args = ["-b", "site", "-s", "build/bake"]
}
RECTANGLE Source1 {
+ site/
}
RECTANGLE Dest1 {
+ ??? (dossier temporaire)
}
RECTANGLE Jetty1 {
+ sert mauvais fichiers
}
JBakeCLI1 --> Source1 : bed
JBakeCLI1 -[#red]x Dest1 : destination ignorée
Jetty1 --> Dest1 : serves
}
package "APRÈS (fix)" {
RECTANGLE JBakeCLI2 {
+ args = ["site", "build/bake", "-s"]
}
RECTANGLE Source2 {
+ site/
}
RECTANGLE Dest2 {
+ build/bake/
}
RECTANGLE Jetty2 {
+ sert les bons fichiers
}
JBakeCLI2 --> Source2 : bed
JBakeCLI2 --> Dest2 : written in
Jetty2 --> Dest2 : works OK
}
@enduml
Quick check with curl
To ensure that the server serves the correct content, a simple`curl`confirm that`index.html`contains`data-bs-theme="light"`and that`build/bake/css/styles.css`weighs exactly 31,402 bytes — identical to the file generated by`bake`.
$ ./gradlew serve
# Dans un autre terminal :
$ curl -s http://localhost:8820/ | grep data-bs-theme
<html ... data-bs-theme="light" ...>
$ curl -I http://localhost:8820/css/styles.css
HTTP/1.1 200 OK
Content-Length: 31402
Content-Type: text/css
The local rendering is nowidentical-pixelto the deployed rendering.
Why was this bug so insidious
Do you see why it was hard to catch?
-
No explicit errorJBake wasn’t crashing. It "worked", just with a bad folder.
-
The build worked :
./gradlew bake`generated the files correctly in`build/bake/. -
The deployment worked:`publishSite`pushed the right content online.
-
Only
servewas broken: the development task, the one we constantly use to iterate. -
The habit of
-key value: as a developer, we are conditioned by years of Unix CLI (-o output`,-i input). JBake CLI is an exception — source and destination are positional.
Conclusion
If you maintain a Gradle plugin that wraps JBake (or any CLI tool),read the arguments documentationeven if you think you know them. An implicit hypothesis (-s = "set destination") can cost you hours of visual debugging.
Here, the fix was literally to change:
args = listOf("-b", src, "-s", dest) // ❌ BUG
en :
args = listOf(src, dest, "-s") // ✅ FIX
Three tokens moved, and my local site is once again as beautiful as the production site.
Lessonwhen the rendering differs between local and prod for no obvious reason, first suspect the pipeline — not the CSS, not the browser, and certainly not the framework. It’s often the step right before rendering that cheats.