Name: modernizer-maven-plugin
Owner: HubSpot
Description: Detect uses of legacy Java APIs
Forked from: gaul/modernizer-maven-plugin
Created: 2018-02-20 17:43:24.0
Updated: 2018-03-30 19:40:35.0
Pushed: 2018-03-30 21:09:29.0
Size: 259
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Modernizer Maven Plugin detects uses of legacy APIs which modern Java versions
supersede.
These modern APIs are often more performant, safer, and idiomatic than the
legacy equivalents.
For example, Modernizer can detect uses of Vector
instead of ArrayList
,
String.getBytes(String)
instead of String.getBytes(Charset)
, and
Guava Objects.equal
instead of Java 7 Objects.equals
.
The default configuration detects
over 100 legacy APIs,
including third-party libraries like
Guava.
To run Modernizer, add the following to the <plugins>
stanza in your pom.xml
then invoke mvn modernizer:modernizer
:
gin>
roupId>org.gaul</groupId>
rtifactId>modernizer-maven-plugin</artifactId>
ersion>1.6.0</version>
onfiguration>
<javaVersion>1.8</javaVersion>
configuration>
ugin>
The <configuration>
stanza can contain several elements:
<javaVersion>
enables violations based on target Java version, e.g., 1.8. For example, Modernizer will detect uses of Vector
as violations when targeting Java 1.2 but not when targeting Java 1.1. Required parameter.<failOnViolations>
fail phase if Modernizer detects any violations. Defaults to true.<includeTestClasses>
run Modernizer on test classes. Defaults to true.<violationsFile>
user-specified violation file. Also disables standard violation checks. Can point to classpath using absolute paths, e.g. classpath:/your/file.xml
.<violationsFiles>
user-specified violations file. The latter files override violations from the former ones, including violationsFile
and the default violations. Can point to classpath using absolute paths, e.g. classpath:/your/file.xml
.<exclusionsFile>
disables user-specified violations. This is a text file with one exclusion per line in the javap format: java/lang/String.getBytes:(Ljava/lang/String;)[B
.<exclusions>
violations to disable. Each exclusion should be in the javap format: java/lang/String.getBytes:(Ljava/lang/String;)[B
.<exclusionPatterns>
violation patterns to disable, specified using <exclusionPattern>
child elements. Each exclusion should be a regular expression that matches the javap format: java/lang/.*
of a violation.<ignorePackages>
package prefixes to ignore, specified using <ignorePackage>
child elements. Specifying foo.bar
subsequently ignores foo.bar.*
, foo.bar.baz.*
and so on.<ignoreClassNamePatterns>
full qualified class names (incl. package) to ignore, specified using <ignoreClassNamePattern>
child elements. Each exclusion should be a regular expression that matches a package and/or class; the package will be / not . separated (ASM's format).To run Modernizer during the verify phase of your build, add the following to
the modernizer <plugin>
stanza in your pom.xml:
cutions>
xecution>
<id>modernizer</id>
<phase>verify</phase>
<goals>
<goal>modernizer</goal>
</goals>
execution>
ecutions>
Command-line flags can override Modernizer configuration and ModernizerMojo documents all of these. The most commonly used flags:
-Dmodernizer.failOnViolations
- fail phase if violations detected, defaults to true-Dmodernizer.skip
- skip plugin execution, defaults to falseAdd @SuppressWarnings("modernizer")
to any class or method to suppress all Modernizer violations within it.
To enable this, add the following to the <dependencies>
stanza in your pom.xml:
endency>
roupId>org.gaul</groupId>
rtifactId>modernizer-annotation-processor</artifactId>
ersion>1.6.0</version>
cope>provided</scope>
pendency>
javac -Xlint:deprecated
detects uses of interfaces with @Deprecated annotationsCopyright © 2014-2018 Andrew Gaul
Licensed under the Apache License, Version 2.0