Build Tools · Lesson 12
Publishing and Packaging Artifacts
Packaging Java Software
A build artifact is a versioned output that can be tested, deployed, or shared. Java projects commonly publish JAR libraries, executable JARs, or WAR files for servlet containers. Reproducible packaging makes releases traceable and rollback practical.
Describing an Artifact
Artifact coordinates identify a published module by group, name, and version. The Java class below models that identity and demonstrates why each part should be explicit.
public record ArtifactCoordinate(String group, String name, String version) {
public String repositoryPath() {
return group.replace('.', '/') + "/" + name + "/" + version;
}
public static void main(String[] arguments) {
ArtifactCoordinate coordinate = new ArtifactCoordinate(
"com.javaacademy", "lesson-service", "1.4.0");
System.out.println(coordinate.repositoryPath());
}
}
Artifact Types
| Artifact | Contains | Typical consumer |
|---|---|---|
| JAR library | Compiled classes and resources | Another Java project |
| Executable JAR | Application and runtime launcher | Container or VM |
| WAR | Web application structure | Servlet container |
| Source JAR | Source files | Developers and debuggers |
Common Mistake and Practices
Common Mistake: Publishing a mutable artifact under the same version repeatedly. Consumers may cache different bytes for the same coordinate, making failures difficult to reproduce.
- Use immutable versioned artifacts.
- Include checksums and release metadata.
- Test the packaged output, not only classes in the build directory.
- Publish source and documentation when useful.
- Separate snapshot and release repositories.
Real-World Use Case
A shared Java Academy content library is published to an internal repository with a semantic version. Service builds consume that exact version and can roll back by selecting the previous artifact.
Quiz Check