maven-dependency-plugin插件的使用
来源:互联网 发布:windows c usleep 编辑:程序博客网 时间:2024/06/16 04:10
http://liugang594.iteye.com/blog/2093082
maven-dependency-plugin是处理与依赖相关的插件。它有很多可用的goal,大部分是和依赖构建、分析和解决相关的goal,这部分goal可以直接用maven的命令操作,例如:mvn dependency:tree、mvn dependency:analyze;这类操作在平时的maven应用中很少会用到。这里主要介绍除此之外的、用得最多的几个操作:copy, copy-dependencies和它们对应的unpack, unpack-dependencies
首先声明插件:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- </plugin>
- </plugins>
- </build>
copy 和 unpack
copy操作可以用来将某个(些)maven artifact(s)拷贝到某个目录下。添加phase和goal如下:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
然后就是配置,copy可以的配置的项比较多,详细的请参考:copy配置。下面是一些常用项说明:
Name Type Since DescriptionartifactItemsList1.0Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier, outputDirectory, destFileName and overWrite.) See Usage for details.outputDirectoryFile1.0Default output location used for mojo, unless overridden in ArtifactItem.Default value is: ${project.build.directory}/dependency.
User property is: outputDirectory.prependGroupIdboolean2.7Prepend artifact groupId during copy
Default value is: false.
User property is: mdep.prependGroupId.
- prependGroupId: 用来指示拷出来的library名字需要不需要加上groupId,默认是不加
- outputDirectory: 用来指定拷出后Libraries的存放地
这里除了artifactItems没有默认值,需要指定外,所有其他的选项都可以被忽略:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- </artifactItems>
- </configuration>
如果想把它拷到lib目录下,可以如下配置:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <outputDirectory>lib</outputDirectory>
- </artifactItem>
- </artifactItems>
- </configuration>
- groupId
- artifactId
- version
- type
- classifier
- outputDirectory
- destFileName
- overWrite
同样的参数,artifactItem里的优先级更高,例如:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <outputDirectory>lib2</outputDirectory>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
unpack和copy类似,只不过它会把拷来的包解开,例如:
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <outputDirectory>lib2</outputDirectory>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
copy-dependencies 和 unpack-dependencies
上面介绍的copy 和 unpack操作是由要拷某个包,这个包需要具体指定要拷哪个包,与当前工程的依赖没有关系。copy-dependencies和它有点类似,但是它是用来拷当前工程的依赖包的,典型的,例如我们有一个web应用,当打成war包的时候,它所有的依赖也需要被打到应用中。
copy-dependencies的参数有很多,详细的可以参考:copy-dependencies Doc,但是几乎所有都有默认值。所以一个最简单的定义如下:
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
也可以使用outputDirectory指定存放在。另外,以下几个参数可以控制哪些依赖将被拷出(或排除):
Name Type Since DescriptionexcludeArtifactIdsString2.0Comma separated list of Artifact names to exclude.User property is: excludeArtifactIds.excludeClassifiersString2.0Comma Separated list of Classifiers to exclude. Empty String indicates don't exclude anything (default).
User property is: excludeClassifiers.excludeGroupIdsString2.0Comma separated list of GroupId Names to exclude.
User property is: excludeGroupIds.excludeScopeString2.0Scope to exclude. An Empty string indicates no scopes (default).
User property is: excludeScope.excludeTransitiveboolean2.0If we should exclude transitive dependencies
Default value is: false.
User property is: excludeTransitive.excludeTypesString2.0Comma Separated list of Types to exclude. Empty String indicates don't exclude anything (default).
User property is: excludeTypes.includeArtifactIdsString2.0Comma separated list of Artifact names to include.
User property is: includeArtifactIds.includeClassifiersString2.0Comma Separated list of Classifiers to include. Empty String indicates include everything (default).
User property is: includeClassifiers.includeGroupIdsString2.0Comma separated list of GroupIds to include.
User property is: includeGroupIds.includeScopeString2.0Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:
- runtime scope gives runtime and compile dependencies,
- compile scope gives compile, provided, and system dependencies,
- test (default) scope gives all dependencies,
- provided scope just gives provided dependencies,
- system scope just gives system dependencies.
User property is: includeScope.includeTypes String2.0Comma Separated list of Types to include. Empty String indicates include everything (default).
User property is: includeTypes.
例如当前工程有以下依赖:
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-script</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-xstream</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jms</artifactId>
- <version>3.2.4.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>3.2.4.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-all</artifactId>
- <version>5.10.0</version>
- </dependency>
- <dependency>
- <groupId>com.thoughtworks.xstream</groupId>
- <artifactId>xstream</artifactId>
- <version>1.4.7</version>
- </dependency>
- <dependency>
- <groupId>org.ogce</groupId>
- <artifactId>xpp3</artifactId>
- <version>1.1.6</version>
- </dependency>
- </dependencies>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <includeScope>compile</includeScope>
- </configuration>
- </plugin>
Copied From: Dependencies Scopesscope/phase->compiletestrunassemblycompileUUUUprovidedU!!!runtime!UUUtest!U!!
说明:最左侧是表示dependency的scope级别,顶行表示maven的阶段,可以看出:compile级别的dependency会在所有阶段都被使用。
要排除所有camel的依赖,如下:
- <configuration>
- <excludeGroupIds>org.apache.camel</excludeGroupIds>
- </configuration>
- <configuration>
- <includeArtifactIds>camel-spring</includeArtifactIds>
- </configuration>
maven-dependency-plugin是处理与依赖相关的插件。它有很多可用的goal,大部分是和依赖构建、分析和解决相关的goal,这部分goal可以直接用maven的命令操作,例如:mvn dependency:tree、mvn dependency:analyze;这类操作在平时的maven应用中很少会用到。这里主要介绍除此之外的、用得最多的几个操作:copy, copy-dependencies和它们对应的unpack, unpack-dependencies
首先声明插件:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- </plugin>
- </plugins>
- </build>
copy 和 unpack
copy操作可以用来将某个(些)maven artifact(s)拷贝到某个目录下。添加phase和goal如下:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
然后就是配置,copy可以的配置的项比较多,详细的请参考:copy配置。下面是一些常用项说明:
Name Type Since DescriptionartifactItemsList1.0Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier, outputDirectory, destFileName and overWrite.) See Usage for details.outputDirectoryFile1.0Default output location used for mojo, unless overridden in ArtifactItem.Default value is: ${project.build.directory}/dependency.
User property is: outputDirectory.prependGroupIdboolean2.7Prepend artifact groupId during copy
Default value is: false.
User property is: mdep.prependGroupId.
- prependGroupId: 用来指示拷出来的library名字需要不需要加上groupId,默认是不加
- outputDirectory: 用来指定拷出后Libraries的存放地
这里除了artifactItems没有默认值,需要指定外,所有其他的选项都可以被忽略:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- </artifactItems>
- </configuration>
如果想把它拷到lib目录下,可以如下配置:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <outputDirectory>lib</outputDirectory>
- </artifactItem>
- </artifactItems>
- </configuration>
- groupId
- artifactId
- version
- type
- classifier
- outputDirectory
- destFileName
- overWrite
同样的参数,artifactItem里的优先级更高,例如:
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <outputDirectory>lib2</outputDirectory>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
unpack和copy类似,只不过它会把拷来的包解开,例如:
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <outputDirectory>lib2</outputDirectory>
- </artifactItem>
- </artifactItems>
- <outputDirectory>lib</outputDirectory>
- </configuration>
copy-dependencies 和 unpack-dependencies
上面介绍的copy 和 unpack操作是由要拷某个包,这个包需要具体指定要拷哪个包,与当前工程的依赖没有关系。copy-dependencies和它有点类似,但是它是用来拷当前工程的依赖包的,典型的,例如我们有一个web应用,当打成war包的时候,它所有的依赖也需要被打到应用中。
copy-dependencies的参数有很多,详细的可以参考:copy-dependencies Doc,但是几乎所有都有默认值。所以一个最简单的定义如下:
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
也可以使用outputDirectory指定存放在。另外,以下几个参数可以控制哪些依赖将被拷出(或排除):
Name Type Since DescriptionexcludeArtifactIdsString2.0Comma separated list of Artifact names to exclude.User property is: excludeArtifactIds.excludeClassifiersString2.0Comma Separated list of Classifiers to exclude. Empty String indicates don't exclude anything (default).
User property is: excludeClassifiers.excludeGroupIdsString2.0Comma separated list of GroupId Names to exclude.
User property is: excludeGroupIds.excludeScopeString2.0Scope to exclude. An Empty string indicates no scopes (default).
User property is: excludeScope.excludeTransitiveboolean2.0If we should exclude transitive dependencies
Default value is: false.
User property is: excludeTransitive.excludeTypesString2.0Comma Separated list of Types to exclude. Empty String indicates don't exclude anything (default).
User property is: excludeTypes.includeArtifactIdsString2.0Comma separated list of Artifact names to include.
User property is: includeArtifactIds.includeClassifiersString2.0Comma Separated list of Classifiers to include. Empty String indicates include everything (default).
User property is: includeClassifiers.includeGroupIdsString2.0Comma separated list of GroupIds to include.
User property is: includeGroupIds.includeScopeString2.0Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:
- runtime scope gives runtime and compile dependencies,
- compile scope gives compile, provided, and system dependencies,
- test (default) scope gives all dependencies,
- provided scope just gives provided dependencies,
- system scope just gives system dependencies.
User property is: includeScope.includeTypes String2.0Comma Separated list of Types to include. Empty String indicates include everything (default).
User property is: includeTypes.
例如当前工程有以下依赖:
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-script</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-xstream</artifactId>
- <version>2.13.2</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jms</artifactId>
- <version>3.2.4.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>3.2.4.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-all</artifactId>
- <version>5.10.0</version>
- </dependency>
- <dependency>
- <groupId>com.thoughtworks.xstream</groupId>
- <artifactId>xstream</artifactId>
- <version>1.4.7</version>
- </dependency>
- <dependency>
- <groupId>org.ogce</groupId>
- <artifactId>xpp3</artifactId>
- <version>1.1.6</version>
- </dependency>
- </dependencies>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.8</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <includeScope>compile</includeScope>
- </configuration>
- </plugin>
Copied From: Dependencies Scopesscope/phase->compiletestrunassemblycompileUUUUprovidedU!!!runtime!UUUtest!U!!
说明:最左侧是表示dependency的scope级别,顶行表示maven的阶段,可以看出:compile级别的dependency会在所有阶段都被使用。
要排除所有camel的依赖,如下:
- <configuration>
- <excludeGroupIds>org.apache.camel</excludeGroupIds>
- </configuration>
- <configuration>
- <includeArtifactIds>camel-spring</includeArtifactIds>
- </configuration>
- maven插件maven-dependency-plugin的使用
- maven插件maven-dependency-plugin的使用
- maven-dependency-plugin插件的使用
- maven-dependency-plugin插件的使用
- maven-dependency-plugin插件的使用
- 解决m2e插件maven-dependency-plugin问题
- M2E插件maven-dependency-plugin问题
- M2E插件maven-dependency-plugin问题
- 解决m2e插件maven-dependency-plugin问题
- 解决m2e插件maven-dependency-plugin问题
- maven-dependency-plugin demo
- maven-dependency-plugin
- maven中tomcat7-maven-plugin插件的使用
- maven中tomcat7-maven-plugin插件的使用
- maven中tomcat7-maven-plugin插件的使用
- maven中tomcat7-maven-plugin插件的使用
- maven中tomcat7-maven-plugin插件的使用
- maven中tomcat7-maven-plugin插件的使用
- Java关键字
- mysql 针对高并发下,同时修改单条数据发生冲突导致数据错误的问题(例如:高并发下单,导致库存为负数)
- HP 1920交换机兼容SFP光模块和光纤跳线解决方案
- 读源码计划
- 关于Oracle11gR2用EXP导出时报EXP-00011错误的解决方法
- maven-dependency-plugin插件的使用
- 取table首列的值
- 使用 webpack 引用 zepto
- boost asio处理tcp和udp的不同之处及要点
- ServiceLoader使用及原理分析
- java设计模式之单例模式
- 阿里云对象存储OSS配置介绍设置,上传代码示例
- 类属性与类方法
- docker安装(一)