Last active
February 17, 2024 00:08
-
-
Save torgeir/6742158 to your computer and use it in GitHub Desktop.
A minimal maven pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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, this is not the minimum, it is a minimal template. its not really a contest, either :D
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
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
Is this really the minimal maven file that will work, or can parts of it be left out?
Cheers
Jérôme