zoukankan      html  css  js  c++  java
  • Maven插件

    Maven Available Plugins

    背景

    • 在使用maven做spring-boot web应用的时候,默认会将resources目录下的资源都打包到jar包中。但是我的应用里resources目录下有些前端库,不想打包到jar包中,不然jar包会一百多兆,去掉这些前端库就只有十几兆了。这方面的优化对部署运维人员来说省时省力不少,做docker镜像也会轻松很多。于是查找了一下maven的插件,看官方文档就很详细,不明白的地方再搜索就好。

    1. Build plugins

    • Build plugins will be executed during the build and they should be configured in the element from the POM.

    1.1 Resources Plugin

    • The Resources Plugin handles the copying of project resources to the output directory.
    • 补充几点:
      • directory标签默认将所有该目录下的资源加入
      • 如果同时使用了includes标签就只会加入includes标签里的内容
      • 对于比较复杂的资源加入可以参考:
        • maven的resources介绍
        • 可以通过使用多个resource标签来实现,比如:
        • 下面的代码本来想只用一个resource来实现只包含父目录下指定子目录的内容,但是一个resource不能实现,使用两个resource即可:
    <resources>
          <resource>
             <directory>src/main/resources/</directory>
              <filtering>true</filtering>
              <!--<includes>-->
                  <!--<include>assets/js/bower_components/bootstrap/dist/</include>-->
                  <!--<include>assets/js/bower_components/jquery/dist/</include>-->
              <!--</includes>-->
             <excludes>
                 <exclude>assets/js/node_modules/**</exclude>
                 <exclude>assets/js/bower_components/**</exclude>
                 <exclude>assets/gentelella/vendors/**</exclude>
                 <exclude>static/gentelella/**</exclude>
             </excludes>
          </resource>
          <resource>
              <directory>src/main/resources/</directory>
              <filtering>true</filtering>
              <includes>
                    <include>assets/js/bower_components/bootstrap/dist/</include>
                    <include>assets/js/bower_components/jquery/dist/</include>
              </includes>
          </resource>
      </resources>
    

    2. Surefire

    • The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats:
    • surefire插件是在测试阶段起作用的。可以添加对应的测试框架依赖,来进行测试,生成测试报告。
    • 使用如下:
     <plugin>
        <!--this plugin and dependency jars are used for testing-->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit4</artifactId>
                <version>2.18.1</version>
            </dependency>
        </dependencies>
        <configuration>
            <additionalClasspathElements>
                <additionalClasspathElement>${base.dir}/cloud.jar</additionalClasspathElement>
                <additionalClasspathElement>${base.dir}/framwork.jar</additionalClasspathElement>
            </additionalClasspathElements>
        </configuration>
    </plugin>
    

    3. 编译插件

    • 使用:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
                <extdirs>${base.lib.dir}</extdirs>
            </compilerArguments>
        </configuration>
    </plugin>
    

    4. jar打包插件

    • 使用:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <outputDirectory>${base.lib.dir}</outputDirectory>
        </configuration>
    </plugin>
    
  • 相关阅读:
    HDU 2376 树形dp|树上任意两点距离和的平均值
    POJ2342 树形dp
    Codeforces 699D Fix a Tree 并查集
    第七届山东省ACM省赛
    [转]override和new的区别
    [转]C#的各种命名规范
    [转]DotNetBar.Bar作为容器使用的方法及Text更新原理
    [转]WPF: ShowDialog() 切换到其他应用窗口后,再切换回来无法让子窗口总在最上方
    c#校验主程序本身的MD5
    [转]WinForm登陆:窗体间的数据传递
  • 原文地址:https://www.cnblogs.com/drawnkid/p/7152097.html
Copyright © 2011-2022 走看看