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-test
How to run "quiet" tests mode:
mvn test -Ptest-quiet
mvn verify -Ptest-quiet
How to generate cobertura site report (generated site in target/site/cobertura/ )
mvn cobertura:cobertura
How to build "config.zip" with configuration for environment "super":
mvn verify -Penvironment-super
How to multiple Profiles:
mvn clean verify -Ptest-quiet -Pintegration-test -Penvironment-super -Pwithout-all
How to switch off generation of "-all.jar" in the submodule-one
mvn clean verify -Pwithout-all
How to exclude sub-modules from processing
mvn --projects "!build-tools,!config" verify
How to run with spotbugs
mvn -Pspotbugs verify
How to run with PMD
mvn -Ppmd verify
How to run OWASP Dependency-Check
mvn -Powasp verify
How to check maven plugin versions
mvn versions:display-plugin-updates
How to analyze dependency
mvn dependency:analyze
Here 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.
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
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.1
Add jar in the local repository:
mvn install:install-file -Dfile=myjar-{version}.jar -DgroupId=my.group.id -DartifactId=my-artifact-it -Dversion={version} -Dpackaging=jar
Add 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-repository
Add "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-repository
Change 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:commit
Change 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:commit
Copy 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\1
Displays all dependencies that have newer versions available.
mvn versions:display-dependency-updates
Released 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