Maven Demo project. Demonstrate:
- Submodules
- build-tools module
- Generated sources
- Build Helper Plugin: http://www.mojohaus.org/build-helper-maven-plugin/
- Integration tests
- Checkstyle
- http://checkstyle.sourceforge.net/
- https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html
- it bound to the "validate" phase
- Spotbugs
- https://spotbugs.github.io/
- https://spotbugs.github.io/spotbugs-maven-plugin/spotbugs-mojo.html
- it bound to the "test" phase
- PMD
- https://pmd.github.io
- https://maven.apache.org/plugins/maven-pmd-plugin/plugin-info.html
- it bound to the "test" phase
- Cobertura
- "quiet" tests mode
- "all-jar", jar which including its dependencies
- Shade Plugin: https://maven.apache.org/plugins/maven-shade-plugin/
- example: /submodule-one/pom.xml
- jar archive of the source files
- Source Plugin: https://maven.apache.org/plugins/maven-source-plugin/
- JVM and Command Line Options with .mvn
- The project local maven repository
- Enforce a minimum version of Maven in pom.xml
- Enforcer Plugin: https://maven.apache.org/enforcer/maven-enforcer-plugin/
- Note: since maven 3.5.0 prerequisites.maven is deprecated, so this solution with maven-enforcer-plugin is only way
- SCM information
- ZIP-artifacts with parameterized configuration files
- example: /config/pom.xml
- Properties Plugin: https://www.mojohaus.org/properties-maven-plugin/
- Assembly Plugin: https://maven.apache.org/plugins/maven-assembly-plugin/
- Echo in maven output
- Maven AntRun Plugin: https://maven.apache.org/plugins/maven-antrun-plugin/
- ${revision} in version
- WARNING. this feature required at least maven 3.5.0-beta-1, otherwise flattenMode=resolveCiFriendliesOnly(flatten-maven-plugin) is not working
- https://issues.apache.org/jira/browse/MNG-5576
- https://maven.apache.org/maven-ci-friendly.html
- This is actually "Maven Continuous Delivery Friendly Versions"-feature, and it also can be used to have only one place in the project which set the version for all modules/sub-modules in the project
- Plugin deactivation
- using phase "none"
- example: /submodule-one/pom.xml
- org.eclipse.m2e
- OWASP Dependency-Check
- maven.build.timestamp.format & maven.build.timestamp
- Git commit-SHA & Branch in MANIFEST.MF
- Bill of Materials (BOM) POM
How to run integration tests:
mvn verify -Pintegration-testHow to run "quiet" tests mode:
mvn test -Ptest-quiet
mvn verify -Ptest-quietHow to generate cobertura site report (generated site in target/site/cobertura/ )
mvn cobertura:coberturaHow to build "config.zip" with configuration for environment "super":
mvn verify -Penvironment-superHow to multiple Profiles:
mvn clean verify -Ptest-quiet -Pintegration-test -Penvironment-super -Pwithout-allHow to switch off generation of "-all.jar" in the submodule-one
mvn clean verify -Pwithout-allHow to exclude sub-modules from processing
mvn --projects "!build-tools,!config" verifyHow to run with spotbugs
mvn -Pspotbugs verifyHow to run with PMD
mvn -Ppmd verifyHow to run OWASP Dependency-Check
mvn -Powasp verifyHow to check maven plugin versions
mvn versions:display-plugin-updatesHow to analyze dependency
mvn dependency:analyzeHere we have a bit tricky configuration to make it possible to use the same configuration files (checks & suppressions) in IDE plugins:
- Eclipse: http://checkstyle.org/eclipse-cs/#!/
- IntelliJ IDEA: https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
Path to the suppressions file from property (checkstyle_checks.xml):
<module name="Checker">
...
<module name="SuppressionFilter">
<property name="file" value="${suppressionsFile}" />
<property name="optional" value="false" />
</module>
...
</module>and in the pom.xml we provide value for the "suppressionsFile" property:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${plugin.version.maven.checkstyle}</version>
<configuration>
...
<propertyExpansion>suppressionsFile=/checkstyle_suppressions.xml</propertyExpansion>
</configuration>You definitely is using Logging in the project. And eventually you (by default) is using debug log-level in unit/integration test (which is fine and wanted). However, it could be unnecessary to get multi-megabyte "debug"-logs when you need to build the whole projects (e.g. "mvn clean install") Solution: use the profile(s) which substitute "default" logging configuration with "quiet"(log-level = error) logging configuration.
Sometimes you are dealing with jar(s) which are not available on maven.org :). And you do not have "private" artifact repository (like Nexus or Artifactory ), where you can simple place it.
How to configure such jar as dependency? Scope system make it possible, but it's very special scope. This scope is working similar with scope provided: e.g. the jar(s) will not included in target war, it will ignored by maven-shade-plugin and so on.
The best option for having local jar files as a dependency is to create local maven repository directly in the project folder (and as result it will be part of your project sources)
- mvn install:install-file with with -DlocalRepositoryPath will do all the work.
- To avoid the "Could not validate integrity of download ... Checksum validation failed, no checksums available" warning - use checksumPolicy = ignore in the pom.xml, which is fine for such local repository.
- in settings.xml, in case of "mirrorOf", it need to avoid
<mirrorOf>*</mirrorOf>. Such configuration will “mirror” all repositories , including the "project local" repositories, which kills the idea. To solve it use<mirrorOf>external:*</mirrorOf>(https://maven.apache.org/guides/mini/guide-mirror-settings.html).
Sometimes it's nice to have ZIP-artifacts with different configuration files (and resources) which will be late used during deployment the project in various environments(e.g. deployment with Jenkins). So, for each environment we want to have specific ZIP, filled with specific (for the environment) configurations, resources and so on. Note: It support default configurations/properties and overriding default configuration/properties.
mvnd - the Maven Daemon: https://github.com/mvndaemon/mvnd
Apache Maven Build Cache Extension: https://github.com/apache/maven-build-cache-extension
Maven BuildTime Profiler: https://github.com/khmarbaise/maven-buildtime-profiler
Takari Extensions: http://takari.io/book/30-team-maven.html
List of predefined Maven properties: https://github.com/cko/predefined_maven_properties/blob/master/README.md
Get artifact in the local repository with all dependencies:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get -Dartifact=io.swagger:swagger-codegen-cli:2.3.1Add jar in the local repository:
mvn install:install-file -Dfile=myjar-{version}.jar -DgroupId=my.group.id -DartifactId=my-artifact-it -Dversion={version} -Dpackaging=jarAdd jar in the project local repository:
mvn install:install-file -Dfile=myjar-{version}.jar -DgroupId=my.group.id -DartifactId=my-artifact-it -Dversion={version} -Dpackaging=jar -DlocalRepositoryPath=../project-maven-repositoryAdd "all" jar in the project local repository :
mvn install:install-file -Dfile=checkstyle-8.12-all.jar -DgroupId=com.puppycrawl.tools -DartifactId=checkstyle -Dversion=8.12 -Dpackaging=jar -Dclassifier=all -DlocalRepositoryPath=../project-maven-repositoryChange property in the pom.xml (including all sub-modules)
mvn org.codehaus.mojo:versions-maven-plugin:2.7:set-property -Dproperty=MyProperty -DnewVersion=MyValue org.codehaus.mojo:versions-maven-plugin:2.7:commitChange version in the pom.xml (including all sub-modules)
mvn org.codehaus.mojo:versions-maven-plugin:2.7:set-DnewVersion=MyNewVersion org.codehaus.mojo:versions-maven-plugin:2.7:commitCopy artifact from the local Maven repository to the folder
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy -Dartifact=net.cactusthorn.gradle:submodules-spring-boot-simple-war:1.0.0:jar:sources -DoutputDirectory=C:\Temp\1Displays all dependencies that have newer versions available.
mvn versions:display-dependency-updatesReleased under the BSD 2-Clause License
Copyright (C) 2018, Alexei Khatskevich
All rights reserved.
Licensed under the BSD 2-clause (Simplified) License (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/BSD-2-Clause