E.g. if I make the BukkitApi jar a dependency for a maven project with depenecy scope set to provided,compile,system, runtime or test
In which scopes will the bukkitAPI be included in the compiled output?
E.g. if I make the BukkitApi jar a dependency for a maven project with depenecy scope set to provided,compile,system, runtime or test
In which scopes will the bukkitAPI be included in the compiled output?
Short version: By default, maven output (in the default target
directory) does not include anything except the compiled code for the current project/module. That is, nothing from dependencies.
Long(er) version: with default jar
packaging and no custom phase configuration. here is how maven behaves on a java project:
compile
phase : the .java
files in the src/main/java/
directory get compiled to .classes
files in the target
directory. Dependencies for the compile
scope get downloaded to your local repository.package
phase : same as 1, plus you'll get a jar
file in the target
directoryinstall
phase : same as 2 you'll get a jar
file in your local repository.So, .jar
files from dependencies are not included in anything by default !
Now, using, for exemple, the assembly
plugin to include dependencies in the output of the package
phase (see Including dependencies in a jar with Maven), you'll normally get this default behavior:
provided
: not includedcompile
(default) : includedsystem
: not includedruntime
: includedtest
: not includedCheckout this link for reference.
EDIT: Just try out this pom with the different scope values on guice
, and you'll see that dependencies are included in the fake-1.0-SNAPSHOT-jar-with-dependencies.jar
when scope is compile
and runtime
(this example does not need any source files)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.linagora</groupId>
<artifactId>fake</artifactId>
<version>1.0-SNAPSHOT</version>
<name>fake</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
<scope>compile</scope>
<!-- system scope needs 'systemPath' attribute as well
<systemPath>/path/to/guice/guice-3.0.jar</systemPath>
<scope>system</scope>
-->
<!-- <scope>runtime</scope> -->
<!-- <scope>test</scope> -->
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
That's not how Maven works. The dependencies just specify the classpath (for compilation, run time, testing). But the dependencies are not included in the output by default. You will have to ship all the dependency jars (at least the ones with scope compile and runtime).
Have a look at the dependency plugin. It provides goals to copy the dependencies.
To create a bundle for shipment, have a look at the assembly plugin (e.g. to create a zip file). It even provides a way to create an all-in-one jar, if that is what you're after.