maven内置变量

${basedir}表示项目根目录,即包含pom.xml文件的目录;

${version}表示项目版本;

${project.basedir}同${basedir};

${project.baseUri}表示项目文件地址;

${maven.build.timestamp}表示项目构件开始时间;

${maven.build.timestamp.format}表示属性${maven.build.timestamp}的展示格式,默认值为yyyyMMdd-HHmm,可自定义其格式,其类型可参考java.text.SimpleDateFormat。

 ${project.build.directory}表示主源码路径;


 ${project.build.sourceEncoding}表示主源码的编码格式;


 ${project.build.sourceDirectory}表示主源码路径;


 ${project.build.finalName}表示输出文件名称;


${project.version}表示项目版本,与${version}相同;


  • ${project.xxx} 当前pom文件的任意节点的内容
  • ${env.xxx} 获取系统环境变量。
  • ${settings.xxx} 指代了settings.xml中对应元素的值。
 

1.maven-compiler-plugin

  设置maven编译的jdk版本,maven3默认用jdk1.5,maven2默认用jdk1.3

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source> <!-- 源代码使用的JDK版本 -->
<target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
<encoding>UTF-8</encoding><!-- 字符集编码 -->
<skipTests>true</skipTests><!-- 跳过测试 -->
</configuration>
</plugin>

2.maven-jar-plugin

<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifest>
<mainClass>com.alibaba.dubbo.container.Main</mainClass>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
<!--自动加载META-INF/spring目录下的所有Spring配置-->
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>

3.maven-source-plugin

打包源码

注意:在多项目构建中,将source-plugin置于顶层或parent的pom中并不会发挥作用,必须置于具体项目的pom中。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

4.maven-resource-plugin

说明:该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

5.maven-dependency-plugin

自动拷贝jar包到target目录

<!-- 依赖插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- ${project.build.directory}为Maven内置变量,缺省为target -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- 表示是否不包含间接依赖的包 -->
<excludeTransitive>false</excludeTransitive>
<!-- 表示复制的jar文件去掉版本信息 -->
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>

6.maven-assembly-plugin

该插件允许用户整合项目的输出,包括依赖,模块,网站文档和其他文档到一个单独的文档,即可用定制化打包。

创建的文档格式包括:zip, tar, tar.gz(tgz), gar.bz2(tbgz2), jar, dir,war 等等。四种预定义的描述器可用:bin, jar-with-dependencies, src, project.


      <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
</assembly>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<!-- TODO: a jarjar format would be better -->
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>src</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
<include>pom.xml</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src</directory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>

Maven常用插件整理的更多相关文章

  1. idea教程视频以及常用插件整理

    最近在同事的强烈安利下把eclipse换成idea了,本以为需要经历一个艰难的过渡期,谁知道不到3天就深感回不去了. 哎,只能说有时候人的惰性是多么可怕! idea实在是太太太强大了. 不要再问原因. ...

  2. maven常用插件pom配置

    一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...

  3. Maven常用插件

    maven利用各种插件来管理构建项目,本文记录下工作中常用到的插件及使用方法.每个插件都会提供多个目标(goal),用于标示任务.各插件配置在pom.xml里,如下: <build> [. ...

  4. maven常用插件总结

    maven本质上是一个插件框架,几乎所有的功能都是通过各种各样的插件来实现的.maven默认会依据项目类型自动把构建时的各阶段(Lifecycle和phase)自动绑定(Lifecycle Mappi ...

  5. maven常用插件配置详解

    常用插件配置详解Java代码    <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...

  6. Maven常用插件简单配置

    好久不见,甚是想念.一日不见,如隔三秋. 从春节到现在已经很久没有回归博客园了,今天回来温习一下maven常用的一些插件的配置,学东西一个很简单的诀窍就是重复重复再重复,这样一定能把知识掌握的很牢靠. ...

  7. Visual Studio Code 常用插件整理

    常用插件说明: 一.HTML Snippets 超级使用且初级的H5代码片段以及提示 二.HTML CSS Support  让HTML标签上写class智能提示当前项目所支持的样式 三.Debugg ...

  8. ionic2——开发利器之Visual Studio Code 常用插件整理

    1.VsCode官方插件地址: http://code.visualstudio.com/docs 2.使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件 添加方法使 ...

  9. IDEA常用插件整理

    1. 集成步骤 1.1. 配置环境变量 变量名:CMDER_ROOT 变量值:D:\Tool\cmder 1.2. IDEA中设置 settings->Tool->Terminal She ...

随机推荐

  1. v$sqlarea,v$sql,v$sqltext这三个视图提供的sql语句有什么区别?

    v$sqltext存储的是完整的SQL,SQL被分割 SQL> desc v$sqltextName                                      Null?    ...

  2. P3554 [POI2013]LUK-Triumphal arch

    \(\color{#0066ff}{ 题目描述 }\) 给一颗树,1号节点已经被染黑,其余是白的,两个人轮流操作,一开始B在1号节点,A选择k个点染黑,然后B走一步,如果B能走到A没染的节点则B胜,否 ...

  3. php 读取excel文件

    首先下载插件PHPExcel (PHPExcel-1.8),以tp5框架为例,将该文件放在verdor文件夹下.然后引入IOFactory文件. 1.读取文件的部分内容(用于固定格式) public ...

  4. typeof 和 instanceof

    typeof 和 instanceof 都是用来判断类型的函数 typeof 对于原始类型来说,除了 null 都可以显示正确的类型 typeof 1 // 'number' typeof '1' / ...

  5. 完美解决:"library not found for - "

    分析原因,解决问题 在Xcode编译的时候,可能会遇到报这个错误"library not found for - ",这是为什么呢? 由于我们在项目中使用了一些第三方的库,如百度的静态库.当Xcode ...

  6. C语言实践

    初学者往往有这样的困惑: 教程也阅读了,知识点也理解了,但是真正编写代码起来无从下手. 连一些基本的小程序都不能完成. 究其原因,就是缺少实践,没有培养起编程思维. 没有处理相关问题的经验. 编程能力 ...

  7. Django之auth模块(用户认证)登陆组件

    auth模块简介 auth模块是对登录认证方法的一种封装,之前我们获取用户输入的用户名及密码后需要自己从user表里查询有没有用户名和密码符合的对象, 而有了auth模块之后就可以很轻松的去验证用户的 ...

  8. linux系统延时和定时任务

    系统延时任务延时任务:只做一次的at命令: 系统定时及延时任务 延时任务:**有输出任务**不会输出到终端上而是发送邮件给你/var/mail/root/执行 mail at          时间 ...

  9. AsyncLocal 与 ThreadLocal ThreadStatic特性简介

    AsyncLocal 与 ThreadLocal [.NET深呼吸]基于异步上下文的本地变量(AsyncLocal) https://www.cnblogs.com/tcjiaan/p/5007737 ...

  10. mc01_IntelliJ IDEA安装与Java项目创建以及Tomcat配置

    IntelliJ IDEA安装与激活 下载地址:http://www.jetbrains.com/idea/ 安装下一步下一步即可,关键是注册激活,该部分分两个步骤: 1. 配置windows hos ...