Maven 中 War/Jar 个包装的 compile/provided 个范围

compile/provided scopes for War/Jar packagings in Maven

说到Maven,我知道:

  1. a compile 当打包为 jar
  2. 时,最终结果中不包含依赖项
  3. 另一方面,如果包装是 war
  4. ,则包含在内
  5. a provided 依赖永远不会包含在最终结果中,无论是 jar 还是 war 包装

例如,在 compile 范围内的依赖项在 jar 打包的情况下,在编译时 Maven 将简单地获取依赖项来自 local/remote 个存储库,没有在最终工件中包含此类依赖项。

如果这些都是正确的,我的问题是:

1) 谁通常会在运行时为 jar 工件提供 compile 作用域依赖?

2) provided 依赖 jarwar 有什么区别包装呢?

1) Who is then usually providing a compile scoped dependency at runtime for a jar artifact?

如果您将 Maven assembly plugin 集成到您的 pom.xml 范围 compile 的依赖项将与您的项目工件一起打包到程序集中。未添加范围为 provided 的依赖项:

这是一个例子。它假设有一个特定的程序集描述符 (projectAssembly.xml),而不是默认的。

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>${artifactId}-${version}-distribution</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>src/main/assembly/projectAssembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>assembly</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

2) What is the difference between a provided dependency in a jar and a war packaging then?

在这两种情况下,都没有添加依赖项。