开发时咱们也许由于各类状况,须要导出maven的全部dependency项,若是去maven仓库找会显的至关繁琐。下面是简单的配置能够帮助咱们轻松的获得全部的依赖jar。html
以前使用:是使用maven-assembly-plugin 插件,发现全部依赖jar所有打到一个jar中,不能知足要求。spring
这里须要添加maven-dependency-plugin 这个插件。apache
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId>
</plugin>
下面主要介绍两种常见使用:<goal> 为copy,和 copy-dependencies 的状况。maven
1.copyspring-boot
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.1</version> <configuration> <artifactItems> <artifactItem> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </artifactItem> </artifactItems> <outputDirectory>target/lib</outputDirectory> </configuration> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy</goal> </goals> </execution> </executions> </plugin>以上代码为copy的设置,此时须要本身指定 artifactItem (也就是须要打包的项)。outputDirectory为jar包输出目录。
此时运行maven打包命令: mvn clean package -Dmaven.test.skip=true。会在target/lib目录下生成咱们配置的jar包。以下图所示:工具
2.copy-dependencies 。测试
copy-dependencies是指当前工程依赖包,它已经关联了咱们pom.xml 中全部dependencies 依赖的jar。而咱们不须要导出的jar包,能够用excludeArtifactIds排除,这里咱们选择排除测试工具包junit 和 spring-boot-devtools 。而后一样能够指定生成目录。spa
spring-boot-devtools
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>target/lib</outputDirectory> <excludeArtifactIds> spring-boot-devtools,junit </excludeArtifactIds> <overWriteSnapshots>true</overWriteSnapshots> </configuration> </execution> </executions> </plugin>
而后就能够获得咱们想要的jar包了。是否是很方便了。
插件
maven-dependency-plugin 的更多使用能够查看:http://maven.apache.org/components/plugins/maven-dependency-plugin/usage.html
component