1. 程式人生 > >請教個 maven-dependency-plugin 的 excludeScope 問題

請教個 maven-dependency-plugin 的 excludeScope 問題

我需求是 copy(copy-dependencies) compile 和 system 範圍的依賴。

我想當然的以為這樣配置能行

<includeScope>compile</includeScope>
<excludeScope>provided</excludeScope>

但事實上 include 不能和 exclude 同時工作,所以只能配置這一個<excludeScope>provided</excludeScope>然後 excludeArtifactIds 排除掉 junit 等

話說有沒有其它簡潔的方法

PS:includeScope 的配置說明

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.

解決方案:

配置兩個就行了

<executions>
    <execution>
        <id>copy-dependencies-runtime</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <!--http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#includeScope-->
            <includeScope>runtime</includeScope>
            <!--依賴傳遞-->
            <excludeTransitive>false</excludeTransitive>
        </configuration>
    </execution>
    <execution>
        <id>copy-dependencies-system</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <includeScope>system</includeScope>
            <!--過濾依賴傳遞-->
            <excludeTransitive>true</excludeTransitive>
        </configuration>
    </execution>
    <execution>
        <id>install</id>
        <phase>install</phase>
        <goals>
            <goal>sources</goal>
        </goals>
    </execution>
</executions>