Skip to content

Instantly share code, notes, and snippets.

@torgeir
Last active February 17, 2024 00:08
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save torgeir/6742158 to your computer and use it in GitHub Desktop.
Save torgeir/6742158 to your computer and use it in GitHub Desktop.
A minimal maven pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gd.wa</groupId>
<artifactId>minimal-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>minimal-pom</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@kunegis
Copy link

kunegis commented Sep 22, 2016

Is this really the minimal maven file that will work, or can parts of it be left out?
Cheers
Jérôme

@sharpedavid
Copy link

I think the author means his "minimal". The minimum will change based on what your needs are. I can get a runnable HelloWorld program with this pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>link.sharpe</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>
> mvn install
> cd target/classes/
> java somePackage.HelloWorld
Hello, world!
>_

A real project will need a bigger pom. Mind you, even a Java EE pom can be small.

@jp26jp
Copy link

jp26jp commented Feb 2, 2018

@LizAinslie
Copy link

@jp26jp, this is not the minimum, it is a minimal template. its not really a contest, either :D

@rzymek
Copy link

rzymek commented Aug 30, 2022

I'd say the working minimal would be:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>g</groupId>
    <artifactId>a</artifactId>
    <version>0</version>
</project>

It works with maven version 3.6.3.

Why? This could be useful for populating a docker layer in a Dockerfile builder:

FROM maven
RUN echo '<project><modelVersion>4.0.0</modelVersion>'\
  '<groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>' > pom.xml \
  && ./mvnw verify clean   # common for all maven projects
COPY pom.xml . 
RUN ./mvnw verify clean  #  project specific dependencies & plugins cached until project's pom.xml changes
COPY . .
RUN ./mvnw verify # run everytime anything changes

@torgeir
Copy link
Author

torgeir commented Jan 10, 2023

This is not the smallest pom.xml you can create. Its a pretty small useful starting point. Trim at will!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment