build-helper-maven-plugin 是Maven 開源插件生態圈中org.codehaus.mojo 這個分組中的,這個分組是次要分組(二級分組);一級分組是org.apache.maven.plugins這一組。
Maven項目的約定
Maven默認只容許指定一個主[Java](http://lib.csdn.net/base/javase "Java SE知識庫")代碼目錄和一個[測試](http://lib.csdn.net/base/softwaretest "軟件測試知識庫")Java代碼目錄。
多個源碼目錄
(例如爲了應對遺留項目),build-helper-maven-plugin的add-source目標就是服務於這個目的,一般它被綁定到默認生命週期的generate-sources
階段以添加額外的源碼目錄。須要強調的是,這種作法仍是不推薦的,由於它破壞了 Maven的約定,並且可能會遇到其餘嚴格遵照約定的插件工具沒法正確識別額外的源碼目錄。attach-artifact
,使用該目標你能夠以classifier的形式選取部分項目文件生成附屬構件,並同時install到本地倉庫,也能夠deploy到遠程倉庫。截止到目前,最新版本爲1.8
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.8</version> </plugin>
該插件提供了多個目標,包括設置主源碼目錄、測試源碼目錄、主資源文件目錄、測試資源文件目錄
等。
如下簡單說一下主資源文件目錄、主源碼目錄的配置,其餘設置大同小異,再也不一一講述。html
配置實例
① 添加額外的源碼路徑java
<project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>some directory</source> //示例以下 <source>src/java/main</source> <source>../usermng-api/src/main/java</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
實例以下圖所示:spring
能夠看到打包usermng-springapi時屬於usermng-api的com.wframe.*也打包進來了。apache
② 添加額外的測試源碼路徑api
<project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>some directory</source> ... </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
③ 添加額外的資源文件路徑maven
<project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-resource</id> <phase>generate-resources</phase> <goals> <goal>add-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/my-resources</directory> <targetPath>my-resources</targetPath> <excludes> <exclude>**/junk/**</exclude> </excludes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
添加額外的測試資源文件路徑使用方式同上,只是修改goal爲add-test-resource。
工具
更多使用參考官網:https://www.mojohaus.org/buil...測試