Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Maven User
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><em>This page is started because I (the first author)</em> <strong><em>don't</em></strong> <em>understand the dependency scope mechanism. In the first version of this page, I am trying to make sense of different sources about the topic. This means the information here is not correct per definition! The intention of this page is to get it correct and clear, so</em> <strong><em>please</em></strong><em>, if you do know something about dependency scopes, change the nonsense below</em> <img class="emoticon emoticon-wink" data-emoticon-name="wink" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/wink.png" alt="(wink)" title="(wink)" /><em>.</em></p> <p><a href="http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">Introduction to the Dependency Mechanism</a></p> <p>Dependencies are defined in the POM, and can be resolved transitively. However, you don't need all dependencies in all situations. That is why dependecies can have a <em>scope</em> defined. Furthermore, there is a tag <code><optional>true</optional></code> you can use for a dependency.</p> <p>In the following table, we explain the behavior of each scope for different goals. We talk about the <strong>current project</strong>, the <strong>dependency</strong> and a <strong>user project</strong>. The <strong>current project</strong> is the project whose POM we are editing. The <strong>dependency</strong> is a project the <strong>user project</strong> directly depends on. A <strong>user project</strong> is a project for which the <strong>current project</strong> is a direct depency. Consequentially, a <strong>user project</strong> has an indirect depency on the <strong>dependency</strong>. We also presume a maven2-based mechanism (goal) to <em>run</em> final projects.</p> <p>The following <em>lifecycle phases</em> are important:</p> <ul> <li><strong>compile</strong>: Compile the main source.</li> <li><strong>test</strong>: Compile the test source and run the tests. This requires the main source to be compiled (the <strong>test</strong> goal depends on the <strong>compile</strong> goal).</li> <li><strong><em>run</em></strong>: (non-existing) goal that runs a final artifact. Obviously, this requires the main sources to be compiled (the <strong><em>run</em></strong> goal depends on the <strong>compile</strong> goal).</li> <li><strong>assembly</strong>: Create an assembly of all kinds off stuff around the artifact. Amongst others, this might contain a <code>lib</code>-directory that contains external libraries the <strong>current project</strong> depends on.</li> </ul> <p>Furthermore, it is important to see that some dependencies that are required for compilation (and testing), are optional for using the artifact on a <strong>user project</strong> or for running it if it is a final project itself. Examples are the dependency of <em>commons-logging</em> on <em>log4j</em> or of <em>hibernate</em> on <em>ehcache</em> and <em>c3po</em> and others. These projects or coded in such a way that they detect whether or not a library is available in the classpath, and use it if it is, but it is not necessary.</p> <p>Also, indirect dependencies are not necessarily needed for compiling a <strong>user project</strong>: the <strong>current project</strong> might depend on the <strong>dependency</strong> internally, but have no mentioning of the <strong>dependency</strong> in its API that is used by the <strong>user project</strong>. Thus, <strong>dependency</strong> is not needed for compiling the <strong>user project</strong>, but it might be for running the final project.</p> <p>The following dependency <em>scopes</em> are supported:</p> <ul> <li><strong>compile</strong>: This <strong>dependency</strong> is needed for compilation of the main source</li> <li><strong>test</strong>: This <strong>dependency</strong> is needed for compiling and running tests. It is not needed for compiling the main source or running the final artifact.</li> <li><strong>runtime</strong>: This <strong>dependency</strong> is needed for running the final artifact. It is not needed for compiling the main source or compiling or running the tests.</li> <li><strong>provided</strong>: This <strong>dependency</strong> is needed for compiling and/or running the artifact but is not necessary to include in the package, because it is <em>provided</em> by the runtime environment - for example, jsp-api.jar is provided by your web application container, so you don't include it in your WEB-INF/lib (for the example of a webapp); or a plugin or optional package that is a prerequisite for your application, but is not bundled with your application.</li> <li><strong>system</strong>: This <strong>dependency</strong> is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessarry in certain edge cases. The system scope includes the <systemPath> element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path: ${JAVA_HOME} for instance.</li> <li><em>tag</em> <code><em><optional /></em></code></li> </ul> <p>Legend:</p> <ul> <li>U: Download and use <strong>dependency</strong> in the classpath. / Dowload and include <strong>dependency</strong> in the assembly.</li> <li>U!O: Download and use <strong>dependency</strong> in the classpath, unless the dependency is <code><optional /></code>. / Dowload and include <strong>dependency</strong> in the assembly, unless the dependency is <code><optional /></code>.</li> <li>!: <strong>dependency</strong> is not used</li> </ul> <p>For the <strong>current project</strong>:</p> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p> scope/phase --> </p></th> <th class="confluenceTh"><p> <code>compile</code> </p></th> <th class="confluenceTh"><p> <code>test</code> </p></th> <th class="confluenceTh"><p> <code><em>run</em></code> </p></th> <th class="confluenceTh"><p> <code>assembly</code> </p></th> </tr> <tr> <th class="confluenceTh"><p> compile </p></th> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> U </p></td> </tr> <tr> <th class="confluenceTh"><p> test </p></th> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> </tr> <tr> <th class="confluenceTh"><p> runtime </p></th> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> U </p></td> </tr> <tr> <th class="confluenceTh"><p> provided </p></th> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> </tr> </tbody></table> <p>For a <strong>user project</strong> that has the <strong>current project</strong> as a dependency with <em>scope</em> <strong>compile</strong>:</p> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p> scope/phase --> </p></th> <th class="confluenceTh"><p> <code>compile</code> </p></th> <th class="confluenceTh"><p> <code>test</code> </p></th> <th class="confluenceTh"><p> <code><em>run</em></code> </p></th> <th class="confluenceTh"><p> <code>assembly</code> </p></th> </tr> <tr> <th class="confluenceTh"><p> compile </p></th> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> U!O </p></td> </tr> <tr> <th class="confluenceTh"><p> test </p></th> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> U </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> </tr> <tr> <th class="confluenceTh"><p> runtime </p></th> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> U!O </p></td> </tr> <tr> <th class="confluenceTh"><p> provided </p></th> <td class="confluenceTd"><p> U!O </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> <td class="confluenceTd"><p> ! </p></td> </tr> </tbody></table> <p>For a <strong>user project</strong> that has the <strong>current project</strong> as a dependency with <em>scope</em> <strong>test</strong>:</p> <p>??</p> <p>For a <strong>user project</strong> that has the <strong>current project</strong> as a dependency with <em>scope</em> <strong>runtime</strong>:</p> <p>??</p> <p>For a <strong>user project</strong> that has the <strong>current project</strong> as a dependency with <em>scope</em> <strong>provided</strong>:</p> <p>??</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced