Giter Site home page Giter Site logo

modernizer-maven-plugin's Introduction

Modernizer Maven Plugin

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.

Configuration

To run Modernizer, add the following to the <plugins> stanza in your pom.xml then invoke mvn modernizer:modernizer:

<plugin>
  <groupId>org.gaul</groupId>
  <artifactId>modernizer-maven-plugin</artifactId>
  <version>1.6.0</version>
  <configuration>
    <javaVersion>1.8</javaVersion>
  </configuration>
</plugin>

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:

<executions>
  <execution>
    <id>modernizer</id>
    <phase>verify</phase>
    <goals>
      <goal>modernizer</goal>
    </goals>
  </execution>
</executions>

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 false

Suppression

Add @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:

<dependency>
  <groupId>org.gaul</groupId>
  <artifactId>modernizer-annotation-processor</artifactId>
  <version>1.6.0</version>
  <scope>provided</scope>
</dependency>

References

  • ASM provides Java bytecode introspection which enables Modernizer's checks
  • javac -Xlint:deprecated detects uses of interfaces with @Deprecated annotations
  • Overstock.com library-detectors detects uses of interfaces with @Beta annotations
  • Checkstyle IllegalInstantiation and Regexp checks can mimic some of Modernizer's functionality
  • Google Error Prone JdkObsolete cheks can mimic some of Modernizer's functionality
  • Gradle Modernizer Plugin is a thin wrapper around this maven modernizer plugin.

License

Copyright (C) 2014-2018 Andrew Gaul

Licensed under the Apache License, Version 2.0

modernizer-maven-plugin's People

Contributors

ankon avatar arentz07 avatar arlol avatar arturgajowy avatar dodgex avatar electrum avatar gaul avatar hgschmie avatar karols avatar lampapetrol avatar nimisha94 avatar simenb avatar simonharrer avatar stephan202 avatar stevie400 avatar vorburger avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

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.