Code Monkey home page Code Monkey logo

java-maven-quickstart's Introduction

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 [email protected]: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 17 project with the following coordinates: com.example, java17-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=java17-project \
    -Dversion=0.0.1-SNAPSHOT \
    -Dname="Project Name" \
    -Ddescription="Project Description" \
    -DjavaVersion=17 \
     archetype:generate

Property javaVersion will set java.version in pom.xml of the generated project.

Its default value is: 17.

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 java17-project
java17-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

java-maven-quickstart's People

Contributors

grumpyf0x48 avatar renovate[bot] avatar spilth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.