This is a Maven Archetype for starting a minimal Java project with Maven.
It adds the following to what was defined in java9-minimal-quickstart:
- Add the possibility to set
java.version
on the command line viajavaVersion
property - Add default
Application.java
and test fileApplicationTest.java
- Add Junit 5 dependency
- Add
jacoco-maven-plugin
plugin for code coverage - Add
maven-enforcer-plugin
andversions-maven-plugin
plugins for obsolete dependencies handling
To create a new Java project using this archetype, you need either:
- Build the archetype locally
- Update Maven configuration in
~/.m2/settings.xml
to add the archetype maven repository
Then you can generate a project with the archetype.
git clone git@github.com:grumpyf0x48/java-maven-quickstart.git && \
cd java-maven-quickstart && \
./mvnw install
To include the archetype maven repository, add the following content in ~/.m2/settings.xml
:
more ~/.m2/settings.xml
...
<profiles>
<profile>
<id>java-maven-quickstart</id>
<repositories>
<repository>
<id>java-maven-quickstart</id>
<url>https://maven.pkg.github.com/grumpyf0x48/java-maven-quickstart</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>java-maven-quickstart</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
...
Having defined the following environment variables:
GITHUB_ACTOR
set to your GitHub usernameGITHUB_TOKEN
set to a personal access token with 'read:packages' scope
For example, to create a Java 21 project with the following coordinates: com.example
, java21-project
, 0.0.1-SNAPSHOT
:
mvn --batch-mode \
-Pjava-maven-quickstart \
-DarchetypeGroupId=org.grumpyf0x48 \
-DarchetypeArtifactId=java-maven-quickstart \
-DarchetypeVersion=0.1-SNAPSHOT \
-DgroupId=com.example \
-DartifactId=java21-project \
-Dversion=0.0.1-SNAPSHOT \
-Dname="Project Name" \
-Ddescription="Project Description" \
-DjavaVersion=21 \
archetype:generate
Property javaVersion
will set java.version
in pom.xml
of the generated project.
Its default value is: 21.
Properties version
, name
and description
are optional and will be set with default values if not set in the previous command.
Then, the generated project will look like:
tree java21-project
java21-project
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── example
│ └── Application.java
└── test
└── java
└── com
└── example
└── ApplicationTest.java
9 directories, 3 files
Once ApplicationTest.java
has no more failing tests:
mvn test
firefox target/site/jacoco/index.html &
mvn versions:display-plugin-updates
mvn versions:display-dependency-updates