skip to content

What is <finalName> in the build section, and how does it relate to coordinates and the deployed artifact name?

level: middleimportance: should knowfreq 35%

answer

  1. base name of target/ output
  2. default = artifactId-version
  3. local file only, not coordinates
  4. deploy reverts to GAV name
  5. handy for Docker/servlet context

basics

~10 s

<finalName> sets the base name of the output file produced in the target/ directory (e.g. target/app.war instead of app-1.0.0.war). It defaults to artifactId-version. It only renames the local build output, not the repository coordinates.

solid answer

~40 s

<finalName>, set under <build>, controls the base filename of the packaged artifact in target/. Its default is ${artifactId}-${version}. Setting <finalName>app</finalName> makes the output target/app.jar (or .war). This is convenient when a downstream tool — a Docker COPY, a servlet container, a deploy script — wants a stable, version-free name. Important nuance: finalName affects only the file written to target/; it does NOT change the GAV coordinates used when the artifact is installed/deployed to a repository. On install/deploy Maven renames the artifact back to the coordinate-based name (artifactId-version[-classifier]). So you cannot use finalName to change how the artifact is addressed by other projects — for that you change the coordinates themselves.

code

xml · 5 lines
xml
<build>
  <finalName>billing-service</finalName>
</build>
<!-- mvn package -> target/billing-service.jar -->
<!-- but installed/deployed as billing-service-1.0.0.jar -->

go deeper

for a junior

Know finalName sets the target/ output filename and defaults to artifactId-version.

for a middle

Explain that it only renames the local build file and does not affect deployed coordinates.

for a senior

Use it sensibly for downstream tooling (Docker, servlet context) and know per-plugin name overrides.

for a principal

Standardize artifact naming for delivery pipelines while preserving coordinate-based resolution semantics.

## What finalName is When Maven packages your project, it writes the result into the `target/` directory. The **base name** of that file is controlled by `<finalName>`, declared inside `<build>`: ```xml <build> <finalName>billing-service</finalName> </build> ``` With that, `mvn package` produces `target/billing-service.jar` instead of the default. ## The default If you don't set it, finalName defaults to: ``` ${project.artifactId}-${project.version} ``` So `billing-service` version `1.0.0` produces `target/billing-service-1.0.0.jar`. ## What it does NOT change This is the key interview point: **finalName only renames the file in `target/`.** It does **not** change the artifact's **coordinates**. When you run `mvn install`/`mvn deploy`, Maven stores the artifact in the repository under the standard coordinate-derived name: ``` <artifactId>-<version>[-<classifier>].<ext> ``` so other projects still resolve it by GAV exactly as before. You cannot rename how an artifact is *addressed* via finalName — only how the local build file is *named*. ## When it's useful - A Dockerfile that does `COPY target/app.jar /app.jar` wants a stable, version-free name. - A servlet container where the WAR filename becomes the context path (e.g. `target/myapp.war` → `/myapp`). - Deploy scripts that don't want to template the version into a filename. ## Per-plugin override Some plugins let you override the output name independently (e.g. maven-war-plugin's `<warName>`, or shade plugin's `<finalName>` for the shaded jar), which can differ from the project finalName. ## Example ```xml <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <warName>${project.artifactId}</warName> </configuration> </plugin> </plugins> </build> ```

  • Does finalName change how other modules depend on this artifact?
    No. Dependencies are resolved by GAV coordinates; finalName only affects the file written to target/. On install/deploy the artifact reverts to the coordinate-based name.
  • What is the default value of finalName?
    ${project.artifactId}-${project.version}.

saying these in an interview costs you the question

  • Claiming finalName changes the artifact's repository coordinates or how it's resolved
  • Confusing finalName with artifactId
  • Thinking finalName affects transitive dependency naming

context