maven提供了丰富的plugins。

maven是一个插件执行的框架。

核心部分的描述:

  1. clean.

    • clean插件。
    • goal:clean
    • 清除构建时生成的文件,文件目录
      • project.build.directory,
      • project.build.outputDirectory,
      • project.build.testOutputDirectory,
      • project.reporting.outputDirectory.
    •   使用示例
      • 忽略错误

        •  忽略清除中的错误

          •   命令行:mvn clean -Dmaven.clean.failOnError=false
          •   <build>
            [...]
            <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <configuration>
            <failOnError>false</failOnError>
            </configuration>
            </plugin>
            [...]
            </build>  默认构建时执行clean命令:
            <project>
              [...]
            <build>
            <plugins>
            <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <executions>
            <execution>
            <id>auto-clean</id>
            <phase>initialize</phase>
            <goals>
            <goal>clean</goal>
            </goals>
            </execution>
            </executions>
            </plugin>
            </plugins>
            </build>
            [...]
            </project>
             
      • 忽略clean操作
        •   命令行:

          mvn clean -Dclean.skip=true
        •   pom配置:
        • <build>
          [...]
          <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.5</version>
          <configuration>
          <skip>true</skip>
          </configuration>
          </plugin>
          [...]
          </build>

            

      • 删除指定文件
        •   pom配置
        • <build>
          [...]
          <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.5</version>
          <configuration>
          <filesets>
          <fileset>
          <directory>some/relative/path</directory>
          <includes>
          <include>**/*.tmp</include>
          <include>**/*.log</include>
          </includes>
          <excludes>
          <exclude>**/important.log</exclude>
          <exclude>**/another-important.log</exclude>
          </excludes>
          <followSymlinks>false</followSymlinks>
          </fileset>
          </filesets>
          </configuration>
          </plugin>
          [...]
          </build>

          路径可以为相对或绝对。   

  2. compiler
    • 编译器:

      •     3.0+: javax.tools.JavaCompiler
      •   3.0-:javac
      • 默认编译:1.5
    • 目标:均属已绑定
      • compile
      • testcompile
    • 使用示例
      • 命令行:

        • mvn compile
        • mvn testcompile
      • pom
        • 自动编译  

          <project>
          ...
          <build>
          <pluginManagement>
          <plugins>
          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
          <!-- put your configurations here
          <configuration> <source>1.4</source>
                    <target>1.4</target>
          </configuration>
          -->
          </configuration>
          </plugin>
          </plugins>
          </pluginManagement>
          </build>
          ...
          </project>

          指定不同的jdk:

        • <project>
          [...]
          <build>
          [...]
          <plugins>
          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
          <executable><!-- path-to-javac --></executable>
          <compilerVersion>1.3</compilerVersion>
          </configuration>
          </plugin>
          </plugins>
          [...]
          </build>
          [...]
          </project> //指定内存:
          <fork>true</fork>
          <meminitial>128m</meminitial>
          <maxmem>512m</maxmem>
          //指定参数
          <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
          或这样的形式:
          <compilerArguments>
          <verbose />
          <bootclasspath>${java.home}\lib\rt.jar</bootclasspath>
          </compilerArguments>    
  3. deploy
    •   goal:

    • 使用
      • distribute设置:
      •  <distributionManagement>
        <repository>
        <id>xx-repository</id>
        <url>ftp://repository.mycompany.com/repository</url>
        </repository>
        </distributionManagement> settings.xml中须包含id对应的配置“
        <servers>
        <server>
        <id>xx-repository</id>
        <username>user</username>
        <password>pass</password>
        </server>
        </servers>
        
        
          
      • pom中buil的设置
      • <build>
        <extensions>
        <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>1.0-beta-6</version>
        </extension>
        </extensions>
        </build>
      • 无pom的deploy
      • mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy-file -Durl=file:///C:/m2-repo \
        -DrepositoryId=some.id \
        -Dfile=path-to-your-artifact-jar \
        -DgroupId=your.groupId \
        -DartifactId=your-artifactId \
        -Dversion=version \
        -Dpackaging=jar \
        -DgeneratePom=false 指定类型的:
        mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy-file -Durl=http://localhost:8081/repomanager/ \
        -DrepositoryId=some.id \
        -Dfile=path/to/artifact-name-1.0.jar \
        -DpomFile=path-to-your-pom.xml \
        -Dfiles=path/to/artifact-name-1.0-debug.jar,path/to/site.pdf \
        -Dclassifiers=debug,site \
        -Dtypes=jar,pdf

          

  4. failsafe
    • 运行junit 集成测试,使用独立的classloader

      • 与sufire的单元测试运行不同,该插件运行的是集成测试
    • 生命周期内会用到该插件的:  
      • pre-integration-test for setting up the integration test environment.
      • integration-test for running the integration tests.
      • post-integration-test for tearing down the integration test environment.
      • verify for checking the results of the integration tests.
    • goal
    • 结果
      • Plain text files (*.txt)
      • XML files (*.xml)
      • ${basedir}/target/failsafe-reports.
    • 使用
      •   

        <plugins>
        [...]
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.16</version>
        <dependencies>
           //设置surefire的provider版本
        <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.16</version>
        </dependency>
          
        </dependencies>
        //设置并发
         <configuration>
        <parallel>methods</parallel>
        <threadCount>10</threadCount>
        </configuration>

        //报表设置:(自定义)

        <configuration>
        <properties>
        <property>
        <name>listener</name>
        <value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
        </property>
        </configuration>
        </plugin> [...] </plugins>

        集成测试 后续再深入探讨  

          

  5. install
    • install Install the built artifact into the local repository.  
    • goal
    • 使用
      • 命令行

        •   

          mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom
          

          校验和设置

        • mvn install -DcreateChecksum=true
          

          install 源码:  

          mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file  -Dfile=path-to-commons-logging-sources.jar \
          -DgroupId=commons-logging \
          -DartifactId=commons-logging \
          -Dversion=1.0.3 \
          -Dpackaging=jar \
          -Dclassifier=sources 
  6. surefire
    • mvn test使用
    • 生成测试结果:
      • Plain text files (*.txt)
      • XML files (*.xml)
      • 目录: ${basedir}/target/surefire-reports.
    • goal:
      • surefire:test 
    • 示例:
      <plugins>
      [...]
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.16</version>
      <configuration>
      <parallel>methods</parallel>
      <threadCount>10</threadCount>
      </configuration>
      </plugin>
      [...]
      </plugins>
      设置路径:
      <configuration>
      <additionalClasspathElements>
      <additionalClasspathElement>path/to/additional/resources</additionalClasspathElement>
      <additionalClasspathElement>path/to/additional/jar</additionalClasspathElement>
      </additionalClasspathElements>
      </configuration>

        

         

  7. site:粗糙带过
    • goal

        • site:site is used generate a site for a single project. Note that links between module sites in a multi module build will not work, since local build directory structure doesn't match deployed site.
        • site:deploy is used to deploy the generated site using Wagon supported protocol to the site URL specified in the <distributionManagement> section of the POM.
        • site:run starts the site up, rendering documents as requested for faster editing. It uses Jetty as the web server.
        • site:stage generates a site in a local staging or mock directory based on the site URL specified in the <distributionManagement> section of the POM. It can be used to test that links between module sites in a multi module build works.
        • site:stage-deploy deploys the generated site to a staging or mock directory to the site URL specified in the <distributionManagement> section of the POM.
        • site:attach-descriptor adds the site descriptor (site.xml) to the list of files to be installed/deployed. For more references of the site descriptor, here's a link.
        • site:jar bundles the site output into a JAR so that it can be deployed to a repository.
        • site:effective-site calculates the effective site descriptor, after inheritance and interpolation.
    • 使用
    • <project>
      ...
      <reporting>
      <plugins>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-project-info-reports-plugin</artifactId>
      <version>2.6</version>
      <reportSets>
      <reportSet>
      <reports><!-- select reports -->
      <report>index</report>
      </reports>
      <reportSet>
      </reportSets>
      </plugin>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>2.9</version>
      <reportSets>
      <reportSet><!-- by default, id = "default" -->
      <reports><!-- select non-aggregate reports -->
      <report>javadoc</report>
      <report>test-javadoc</report>
      </reports>
      </reportSet>
      <reportSet><!-- aggregate reportSet, to define in poms having modules -->
      <id>aggregate</id>
      <inherited>false</inherited><!-- don't run aggregate in child modules -->
      <reports>
      <report>aggregate</report>
      </reports>
      </reportSet>
      </reportSets>
      </plugin>
      </plugins>
      </reporting>
      ...
      </project>

        

        先暂时这些,后续再补上。

maven-plugins说明的更多相关文章

  1. Maven Plugins常用配置

    官方文档:http://maven.apache.org/plugins/index.html# 这里主要介绍compiler插件的配置.http://maven.apache.org/plugins ...

  2. maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang

    maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default- ...

  3. Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (dist) on project hadoop-kms: An Ant BuildException has occured

    编译cdh版hadoop2.5.0出现的问题 系统: CentOs66 64位 JDK:1.7 Maven: 3.0.5 Protobuf: libprotoc 2.5.0 编译命令: mvn pac ...

  4. eclipse加载maven工程提示pom.xml无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3解决方案

    pom文件提示信息: Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from http:/ ...

  5. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project LogTest: Compilation failure -> [Help 1]

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default ...

  6. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:

    security-sdk-1.0.jar已经存在于D:/secServerSDK-test/src/main/resources/lib下 报错如下: xxxxxx@xxxxxxxx /d/secSe ...

  7. maven Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repositories 解决

    报错:Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repos ...

  8. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of 3: mojo org.apache.maven.plugins:

    问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (defau ...

  9. CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved

    CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin ...

  10. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on ...

随机推荐

  1. Django学习---ajax

    Ajax 应用场景:我们在输入表单进行提交的时候往往会判断输入的数据形式是否正确,这个时候如果我们点击了提交就会刷新页面.如果我们不想要它刷新页面,让它“悄悄的提交数据”,这个时候我们就需要使用aja ...

  2. G++ 4.4.7 无法编译模板程序,Vs可以,和解?智者尾部留言,本人第一次使用vs pro,通常并且习惯在linux下写些小东西,虽然程序简单;

    vs 模板编译运行Ok \ linux g++ 4.4.7编译模板测试程序,报无法定义 template <typename or class 中的 AnyType> 类型的数据 Exam ...

  3. 【LA2531 训练指南】足球联赛 【最大流】

    题意: 有n支队伍进行比赛,每支队伍需要打的比赛数目相同.每场比赛恰好一支队伍胜,另一支败.给出每支队伍目前胜的场数和败的场数,以及每两支队伍还剩下的比赛场数,确定所有可能的冠军的球队.(获胜场数最多 ...

  4. 高性能Web服务器Nginx的配置与部署研究(4)Nginx常用命令

    1. 启动 Nginx poechant@ubuntu:sudo ./sbin/nginx 2. 停止 Nginx poechant@ubuntu:sudo ./sbin/nginx -s stop ...

  5. 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!

    1 学习 Nginx 模块开发需要有哪些准备? 需要的预备知识不多,有如下几点: 有过一些 C 语言的编程经历: 知道 Nginx 是干嘛的,并有过编写或改写 Nginx 的配置文件的经历. OK,就 ...

  6. winfrom 循环播放图片

    没啥新东西了,就是遍历和匹配文件名然后获取对象,放到picturebox里面 选中listview中想要查看的图片,然后点击查看按钮,进行↓代码. if (listView1.SelectedItem ...

  7. Oracle VM VirtualBox 部署CS devcloud2 开发环境

    Setting up (VirtualBox) 1. Get the new DevCloud 2.0 virtual appliance. The new image was created usi ...

  8. 修改apache的默认访问路径

  9. Ubuntu命令行下安装、卸载、管理软件包的方法

    一.Ubuntu中软件安装方法 1.APT方式 (1)普通安装:apt-get install softname1 softname2 -; (2)修复安装:apt-get -f install so ...

  10. hadoop错误:Does not contain a valid host:port authority

    hadoop环境部署完,执行hdfs zkfc -formatZK命令时,提示如上图所示错误 错误内容: [root@study_1_1 hadoop]# hdfs zkfc -formatZK Ex ...