MAVEN learning (six) - maven common plug-ins

We use maven to do some daily work of development time, I was simply trying to take advantage of some of the convenience brought by this tool. For example, it brings dependency management, packaging and deployment to help us run. Here are a few common plug-ins and is commonly used in projects related to these steps.

maven-compile-plugin

    This plug-in just as the name suggests this is used to compile the source code. Initially came across this plugin is that sometimes when we downloaded some projects need to be compiled, such as we enter the command: mvn install, but the system compile time error, the error message is as follows:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project springJMS: Compilation failure: Compilation failure:  
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/huangbowen/net/jms/MessageSender.java:[6,1] error: annotations are not supported in -source 1.3  
[ERROR]   
[ERROR] (use -source 5 or higher to enable annotations)  
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/net/EmbedBrokerApp.java:[5,7] error: static import declarations are not supported in -source 1.3  
[ERROR] -> [Help 1]  
[ERROR]   
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
[ERROR] Re-run Maven using the -X switch to enable full debug logging.  
[ERROR]   
[ERROR] For more information about the errors and possible solutions, please read the following articles:  
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

    Error display from we can see, this is because the compiler version 1.3 is the default when using javac, the code is too old is not supported. To fix this, we need to set the version of the compiler. The solution to this problem is relatively simple, it is to add the following plug-ins directly behind the plug-in parts, such as the following section, the version of the compiler is set to 1.6:

<build>  
      <plugins>  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <version>2.3.2</version>  
            <configuration>  
          <encoding>UTF-8</encoding> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>

 

<-! Compiler plugin -> 
<plugin> 
    <groupId> org.apache.maven.plugins </ groupId> 
    <artifactId> Compiler-Maven-plugin </ artifactId> 
    <Version> 3.5 . 1 </ Version> 
    <the Configuration > 
        <! - source style using 1.7 style -> 
        <Source> 1.8 </ Source> 
        <target> 1.8 </ target> 
        <encoding> UTF- 8 </ encoding> 
        <! - must be added compilerArgument configured to use the method JFinal Controller function with parameter -> 
        <compilerArgument> -parameters </ compilerArgument> 
        <-! <compilerArgs> ->
            <!--<compilerArg>-parameters</compilerArg>-->
        <-! </ compilerArgs> ->! - </ compilerArgs> -> 
        <-! compiled over code compiled classes ->
        <excludes> 
            <-! exclude application compiled classes -> 
            <the exclude> ** / ApplicationCodeGenerator.java </ the exclude> 
        </ excludes> 
    </ Configuration> 
</ plugin>
<plugins> 
    <!-- Maven 编译错误 Dynamic Web Module 3.0 requires Java 1.6 or newer 解决方案 -->
        <!-- define the project compile level ,指定编译级别1.7--> 
        <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-compiler-plugin</artifactId> 
            <version>2.3.2</version> 
            <configuration> 
                <source>1.7</source> 
                <target>1.7</target> 
            </configuration> 
        </plugin> 
    </plugins> 

 

The following plug-ins are commonly used in the project maven plugin, when you can use the Internet to find specific use on their own, not in this breakdown:

maven-resources-plugin package allocation of resources

maven-surefire-plugin test

jetty-maven-plugin to run jetty

maven-jar-plugin jar packaging (maven-jar-plugin package contains only the generated class files, and maven-resources-plugin, maven-dependency-plugin conjunction)

maven-dependency-plugin replication is dependent package to the specified directory jar

maven-war-plugin package to fight executable war

maven-assembly-plugin fight executable package (there are bug, might jar package conflicts, not recommended)

maven-shade-plugin fight executable package (recommended) 

spring-boot-maven-plugin springBoot project package (before the implementation of the general maven jar packaging command, jar package name suffix will generate increased .orginal, then in this jar package, based on the generated that contains all the configuration files and dependencies of executable jar package)

maven-source-plugin generating source package

cobertura-maven-plugin test coverage

sonar-maven-plugin sonar detection codes

 

Guess you like

Origin www.cnblogs.com/gllegolas/p/11611455.html