Skip to content

An Archetype for generating a minimal Java Maven project.

Notifications You must be signed in to change notification settings

grumpyf0x48/java-maven-quickstart

 
 

Repository files navigation

Java Maven Quickstart

Java CI

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 via javaVersion property
  • Add default Application.java and test file ApplicationTest.java
  • Add Junit 5 dependency
  • Add jacoco-maven-plugin plugin for code coverage
  • Add maven-enforcer-plugin and versions-maven-plugin plugins for obsolete dependencies handling

Usage

To create a new Java project using this archetype, you need either:

Then you can generate a project with the archetype.

Build the archetype locally

git clone git@github.com:grumpyf0x48/java-maven-quickstart.git && \
    cd java-maven-quickstart && \
    ./mvnw install

Update Maven configuration

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 username
  • GITHUB_TOKEN set to a personal access token with 'read:packages' scope

Generate a project using the archetype

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

Run the tests

Once ApplicationTest.java has no more failing tests:

mvn test

Check the code coverage

firefox target/site/jacoco/index.html &

Check obsolete plugins

mvn versions:display-plugin-updates

Check obsolete dependencies

mvn versions:display-dependency-updates

About

An Archetype for generating a minimal Java Maven project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Shell 50.3%
  • Java 49.7%