This artifact is a simple pom.xml
configuration file that eases the sometimes painful process of
setting up the basic infrastructure for a new Java project using Maven.
Simply use this artifact as the parent project. Add the following in your pom.xml
:
<parent>
<groupId>io.github.luiinge</groupId>
<artifactId>maven-java-starter</artifactId>
<version>11.3.0</version>
</parent>
If your project already have a parent project, you may modify the parent pom.xml
, if it is a
viable option. As a last resort, you always can copy the configuration of this artifact and paste
it into yours.
The major segment of the artifact version indicates the Java version that the configuration is tuned for (currently only Java 11), but nothing prevents you from using it with other versions
- Sets source and output encodings to
UTF-8
- Sets the specific Java version
- Includes the SL4FJ API as a
compile
dependency - Includes Log4J, JUnit 4, Hamcrest and AssertJ as
test
dependencies - Uses Surefire and Failsafe for testing in the build lifecycle. Also uses JaCoCo as agent in order to collect coverage data
- Generates JAR files with the source
- Pre-configured profiles:
- Static analysis tools including Spotbugs, Checkstyle, and PMD
- Obsolete dependencies analysis
- Javadoc generation
- SonarCloud analysis
- OSSRH deployment
The pre-configured profiles include one o more Maven plugins into the build. Each profile can be activated by using either its profile identifier, or a property with the same name. The following invokations are equivalent:
mvn clean install -Pcheck.code.pmd,sonar
mvn clean install -Dcheck.code.pmd -Dsonar
So, you may also enable certain profiles declaring the proper property:
<properties>
<check.code.pmd>true</check.code.pmd>
<sonar>true</sonar>
</properties>
For an exhaustive list of every configuration option of each plugin, please check the corresponding links provided at each profile section.
Display new versions of the project dependencies using Versions Maven Plugin.
Also check vulnerabilities in dependencies using OWASP Dependency Check.
Check code quality using Apache Maven Checkstyle Plugin
Check code quality using Apache Maven PMD Plugin
Check code quality using SpotBugs Maven Plugin
Enable every check.code.xxx
profile at the same time (just out of convenience)
Perform a SonarCloud scan actions after completing the verify
goal (since
test results are part of the source data). You can configure the server connection properties using
the following properties (although is pre-configured with the usual values):
<sonar.projectKey>${project.organization.name}_${project.artifactId}</sonar.projectKey>
<sonar.organization>${project.organization.name}</sonar.organization>
<sonar.host.url>http://sonarcloud.io</sonar.host.url>
Tips:
- You may want to specify the code branch by adding the argument
-Dsonar.branch.name=...
. - You should establish the environment variable
SONAR_TOKEN
(different for each project). - You can include the results of other static analysis in your Sonar report by enabling the specific
profile along with the
sonar
profile. For example, in order to notify the code coverage with JaCoCo, the command should be something like:
mvn clean verify -Psonar,generate.reports.jacoco
Using the following profiles, reports are not generated at the
site
phase but as soon as their source data is available.
Generate coverage report using JaCoCo Maven Plugin.
The output directory is defined by the property project.docdir.coverage
.
Generate Javadoc documentation using Apache Maven Javadoc Plugin
. The preset configuration is set to only generate documentation for public methods and classes
that are not in a *.internal
nor *.impl
package. The output directory is defined by the
property project.docdir.javadoc
.
Generate a project dependencies report using Apache Maven Project Info Reports Plugin
. The output directory is defined by the property project.docdir
.
Generate the Checkstyle analysis report using Apache Maven Checkstyle Plugin
. The output directory is defined by the property project.docdir
.
Generate the Checkstyle analysis report using Apache Maven PMD Plugin
. The output directory is defined by the property project.docdir
.
Generate the Checkstyle analysis report using SpotBugs Maven Plugin
. The output directory is defined by the property project.docdir
.
Enable every generate.reports.xxx
profile at the same time (just out of convenience)
This profile (enabled by using -P ossrh
) generates the artifacts required in order to
deploy the project to the Sonatype Open Source Software Repository Hosting according to
Sonatype Requeriments and
Configuring Your Project for Deployment.
(You would require configuring your local settings.xml
file regardless)
Every dependency version is set using a property, so that inherited modules can override specific versions without change the overall configuration.
<!-- dependencies -->
<slf4j-api.version>1.7.30</slf4j-api.version>
<junit.version>4.13.1</junit.version>
<hamcrest.version>2.2</hamcrest.version>
<log4j.version>2.13.0</log4j.version>
<assertj.version>3.16.1</assertj.version>
<!-- build plugins' versions -->
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.surefire.version>2.18.1</maven.surefire.version>
<maven.failsafe.version>2.18.1</maven.failsafe.version>
<maven.jacoco.version>0.8.2</maven.jacoco.version>
<maven.clean.version>3.1.0</maven.clean.version>
<maven.source.version>3.0.1</maven.source.version>
<maven.javadoc.version>3.0.0</maven.javadoc.version>
<maven.surefire-report.version>3.0.0-M5</maven.surefire-report.version>
<maven.info-report.version>3.1.0</maven.info-report.version>
<maven.gpg.version>1.5</maven.gpg.version>
<maven.nexus-staging.version>1.6.7</maven.nexus-staging.version>
<maven.sonar.version>3.7.0.1746</maven.sonar.version>
<maven.checkstyle.version>3.1.1</maven.checkstyle.version>
<maven.pmd.version>3.13.0</maven.pmd.version>
<maven.spotbugs.version>4.0.4</maven.spotbugs.version>
<maven.versions.version>2.8.1</maven.versions.version>
Due to the Maven inheritance mechanism, all sections of this pom.xml
file are inherited,
included those which have nothing to do with the primary intents of this configuration. At the same
time, some specific sections must be fulfilled to this project be in a public repository, so they
cannot be empty by default.
Because of that, it is strongly recommended overriding the following sections in every pom.xml
that use this one as a parent:
name
description
url
organization
licenses
issueManagement
developers
scm
However, in the specific case your project is fully hosted by Github, you may benefit from parts of
this configuration, since the url
, issueManagement
and scm
would be already prepared. Those
sections are defined using the following properties, which you can redefine:
<github.host>github.com</github.host>
<github.user>${project.organization.name}</github.user>
<github.project>${project.artifactId}</github.project>
<github.user.url>https://${github.host}/${github.user}</github.user.url>
<github.project.url>${github.user.url}/${github.project}</github.project.url>
- Luis Iñesta Gelabert | luiinge@gmail.com
If you want to contribute to this project, visit the Github project. You can open a new issue / feature request, or make a pull request to consider. You will be added as a contributor in this very page.
If you have found any defect in this software, please report it in Github project Issues. There is no guarantee that it would be fixed in the following version but it would be addressed as soon as possible.
MIT License
Copyright (c) 2020 Luis Iñesta Gelabert - luiinge@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.