Maven common plugin configuration and use

Mainly introduces the configuration and use of several common third-party plug-ins (cobertura, findbugs, source, assembly, plug-in development) of Maven , and then introduces Maven

 

Maven is essentially a plugin framework, all of its work is done by plugins, and each plugin can have multiple goals.
In addition to the built-in plug-ins, there are many more mature third-party plug-ins, we are also very easy to start simple plug-in development, the following one by one

 

1 Self-contained plug-ins
The core plug-ins that come with maven are Build plugins and Reporting plugins.
Mvn compile actually uses the maven-compiler-plugin to compile the source code, and other phases also use the corresponding plug-ins
. For the core plug-ins that come with maven, see: http://maven.apache.org/plugins/index.html

 

2 Third-party plug-ins
2.1 There are many mature third-party plug-ins for maven,
such as jetty, for web development, use jetty as a container
native, compile c and c++ code
sql, execute sql scripts
, see more: http://maven.apache.org/plugins/index .html#Outside_The_Maven_Land
The following is a detailed introduction to the unit test coverage plugin cobertura, findbugs

 

2.2 maven2 cobertura plugin
2.2.1 cobertura

cobertura is a tool for calculating test coverage of java code, based on jcoverage. It can calculate the line coverage and branch coverage of each class, package, and the entire project, as well as the code complexity (Cyclomatic complexity), and generate a report in the form of html or xml, allowing users to easily view the unit test coverage of the code. The principle of cobertura is to instrument and then calculate the class file.

 

2.2.2 Introduction to the cobertura plug-in of maven2 The plug
-in address is http://mojo.codehaus.org/cobertura-maven-plugin/index.html
a. First, add the following configuration to the pom

<!-- Crayon Syntax Highlighter v_2.7.2_beta -->

<!-- [Format Time: 0.0013 seconds] -->

 
b. Run goal
to the project root directory and run mvn cobertura:cobertura to instrument class files, test, and generate coverage reports
. The goals supported by cobertura are as follows:
cobertura:check Check the Last Instrumentation
Results.cobertura:clean Clean up rogue files that cobertura maven plugin is tracking.
cobertura:dump-datafile Cobertura Datafile Dump Mojo.
cobertura:instrument Instrument the compiled classes.
cobertura:cobertura Instruments, Tests, and Generates a Cobertura Report.
c. Generate report files in target\site\cobertura directory , open index.html to view the specific report
mvn cobertura: test phase will be executed before cobertura is executed, that is, one-sided code will be executed

 

2.3 findbugs plugin of maven2
2.3.1 findbugs

It is a tool for statically checking java code. It checks the bugs in the code according to the expressions of some bugs, and can customize the inspection rules.

 

2.3.2 Introduction to the findbugs plugin of maven2 The
plugin address is http://mojo.codehaus.org/findbugs-maven-plugin/index.html
a. First, add the following configuration to the pom The configuration of
different goals is slightly different, you can adjust it yourself , the following describes the configuration of mvn findbugs:findbugs

<!-- Crayon Syntax Highlighter v_2.7.2_beta -->

<!-- [Format Time: 0.0012 seconds] -->

 
b. Run the goal
to the project root directory and run mvn findbugs:findbugs to start checking and generate a bugs report
. The goals supported by findbugs are as follows:

<!-- Crayon Syntax Highlighter v_2.7.2_beta -->

<!-- [Format Time: 0.0035 seconds] -->

c. Generate a report file in the target\site\findbugs directory, open index.html to view the specific report
mvn findbugs: findbugs is bound to the compile phase, that is, it is automatically checked at compile time

 

2.4 maven's source plugin
2.4.1 source

The 2.4.2 pom configuration used to package the project into a jar package with source code is as follows

<!-- Crayon Syntax Highlighter v_2.7.2_beta -->

<!-- [Format Time: 0.0022 seconds] -->

Running mvn clean install directly will print two packages under the target, and the one with ***-sources.jar is the source package

 

2.5 Maven's assembly plugin
2.5.1 assembly

It can be used to package the jar packages and projects that the project depends on into one jar package.
2.5.2 The pom configuration is as follows

<!-- Crayon Syntax Highlighter v_2.7.2_beta -->

<!-- [Format Time: 0.0008 seconds] -->

Running mvn assembly:assembly directly will show the jar package of ***-with-dependencies.jar under the target

 

2.6 Plug-in development
Maven's plug-in development is quite simple, you can refer to http://trinea.iteye.com/blog/1171957

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326307911&siteId=291194637