0
votes

Talking about Maven, I know that:

  1. a compile dependency is not included in the final outcome when packaging is jar
  2. on the other hand, it is being included if packaging is war
  3. a provided dependency is never included in the final outcome neither with jar nor with war packaging

For example, in the case of a compile scoped dependency in a jar packaging, at compile time Maven will simply fetch the dependency from local/remote repositories, without including such dependency in the final artifact.

If all this is correct, my questions are:

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

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

1
See the concept of executable JARs stackoverflow.com/questions/574594/…, and see also stackoverflow.com/questions/6646959/…Tunaki

1 Answers

1
votes

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

If you integrate the Maven assembly plugin to your pom.xml, the dependencies with scope compile will be packed to the assembly, together with your projects artifact. The dependencies with scope provided are not added:

Here is an example. It assumes that there is an specific assembly descriptor (projectAssembly.xml), not a default one.

    <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?

In both cases, the dependencies aren't added.