CINXE.COM

Maven Artifacts – Maven

<!DOCTYPE html> <!-- | Generated by Apache Maven Doxia Site Renderer 2.0.0 from content/markdown/repositories/artifacts.md at 2024-12-17 | Rendered using Apache Maven Fluido Skin 2.0.1 --> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" /> <title>Maven Artifacts – Maven</title> <link rel="stylesheet" href="../css/apache-maven-fluido-2.0.1.min.css" /> <link rel="stylesheet" href="../css/site.css" /> <link rel="stylesheet" href="../css/print.css" media="print" /> <script src="../js/apache-maven-fluido-2.0.1.min.js"></script> <!-- Matomo --> <script> var _paq = window._paq = window._paq || []; _paq.push(['disableCookies']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://analytics.apache.org/"; _paq.push(['setTrackerUrl', u+'/matomo.php']); _paq.push(['setSiteId', '3']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'/matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> </head> <body> <div class="container-fluid container-fluid-top"> <header> <div id="banner"> <div class="pull-left"><div id="bannerLeft"><h1><a href="https://www.apache.org/"><img class="class java.lang.Object" src="../images/apache-maven-project.png" /></a></h1></div></div> <div class="pull-right"><div id="bannerRight"><h1><a href=".././"><img class="class java.lang.Object" src="../images/maven-logo-black-on-white.png" /></a></h1></div></div> <div class="clear"><hr/></div> </div> <div id="breadcrumbs"> <ul class="breadcrumb"> <li><a href="https://www.apache.org/" class="externalLink">Apache</a><span class="divider">/</span></li> <li><a href="../index.html">Maven</a><span class="divider">/</span></li> <li class="active">Maven Artifacts <a href="https://github.com/apache/maven-site/tree/master/content/markdown/repositories/artifacts.md"><img src="../images/accessories-text-editor.png" alt="Edit" /></a></li> <li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2024-12-17</li> <li class="pull-right"><span class="divider">|</span> <a href="../scm.html">Get Sources</a></li> <li class="pull-right"><a href="../download.cgi">Download</a></li> </ul> </div> </header> <div class="row-fluid"> <header id="leftColumn" class="span2"> <nav class="well sidebar-nav"> <ul class="nav nav-list"> <li><a href="../index.html">Welcome</a></li> <li><a href="https://www.apache.org/licenses/" class="externalLink">License</a></li> <li class="nav-header">About Maven</li> <li><a href="../what-is-maven.html">What is Maven?</a></li> <li><a href="../maven-features.html">Features</a></li> <li><a href="../download.html">Download</a></li> <li><a href="../users/index.html"><span class="icon-chevron-right"></span>Use</a></li> <li><a href="../docs/history.html">Release Notes</a></li> <li class="nav-header">Documentation</li> <li><a href="../plugins/index.html">Maven Plugins</a></li> <li><a href="../extensions/index.html">Maven Extensions</a></li> <li><a href="../guides/index.html">Index (category)</a></li> <li><a href="../users/index.html"><span class="icon-chevron-right"></span>User Centre</a></li> <li><a href="../plugin-developers/index.html"><span class="icon-chevron-right"></span>Plugin Developer Centre</a></li> <li><a href="../repositories/index.html"><span class="icon-chevron-down"></span>Maven Repository Centre</a> <ul class="nav nav-list"> <li><a href="../repository/index.html"><span class="icon-chevron-right"></span>Maven Central Repository</a></li> <li class="active"><a>Maven Artifacts</a></li> <li><a href="../repositories/metadata.html">Maven Metadata</a></li> <li><a href="../repositories/layout.html">Maven Layout</a></li> <li><a href="../repositories/local.html">Maven Local Repository</a></li> <li><a href="../repositories/remote.html">Maven Remote Repositories</a></li> </ul></li> <li><a href="../developers/index.html"><span class="icon-chevron-right"></span>Maven Developer Centre</a></li> <li><a href="../articles.html">Books and Resources</a></li> <li><a href="../security.html">Security</a></li> <li class="nav-header">Community</li> <li><a href="../community.html">Community Overview</a></li> <li><a href="../project-roles.html">Project Roles</a></li> <li><a href="../guides/development/guide-helping.html">How to Contribute</a></li> <li><a href="../users/getting-help.html">Getting Help</a></li> <li><a href="../issue-management.html">Issue Management</a></li> <li><a href="../scm.html">Getting Maven Source</a></li> <li><a href="../team.html">The Maven Team</a></li> <li class="nav-header">Project Documentation</li> <li><a href="../project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li> <li class="nav-header">Maven Projects</li> <li><a href="../ref/current">Maven</a></li> <li><a href="../archetypes/index.html">Archetypes</a></li> <li><a href="../extensions/index.html">Extensions</a></li> <li><a href="../pom/index.html">Parent POMs</a></li> <li><a href="../plugins/index.html">Plugins</a></li> <li><a href="../skins/index.html">Skins</a></li> <li><a><span class="icon-chevron-down"></span>Components</a> <ul class="nav nav-list"> <li><a href="../archetype/index.html">Archetype</a></li> <li><a href="../resolver/index.html">Artifact Resolver</a></li> <li><a href="../doxia/index.html">Doxia</a></li> <li><a href="../maven-indexer/index.html">Indexer</a></li> <li><a href="../jxr/index.html">JXR</a></li> <li><a href="../plugin-testing/index.html">Plugin Testing</a></li> <li><a href="../plugin-tools/index.html">Plugin Tools</a></li> <li><a href="../apache-resource-bundles/index.html">Resource Bundles</a></li> <li><a href="../scm/index.html">SCM</a></li> <li><a href="../shared/index.html">Shared Components</a></li> <li><a href="../surefire/index.html">Surefire</a></li> <li><a href="../wagon/index.html">Wagon</a></li> </ul></li> <li class="nav-header">ASF</li> <li><a href="https://www.apache.org/foundation/how-it-works.html" class="externalLink">How Apache Works</a></li> <li><a href="https://www.apache.org/foundation/" class="externalLink">Foundation</a></li> <li><a href="https://privacy.apache.org/policies/privacy-policy-public.html" class="externalLink">Data Privacy</a></li> <li><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink">Sponsoring Apache</a></li> <li><a href="https://www.apache.org/foundation/thanks.html" class="externalLink">Thanks</a></li> </ul> </nav> <div class="well sidebar-nav"> <div id="poweredBy"> <div class="clear"></div> <div class="clear"></div> <a href="https://maven.apache.org/" class="builtBy" target="_blank"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> </div> </div> </header> <main id="bodyColumn" class="span10"> <section><a id="Maven_Artifacts"></a> <h1>Maven Artifacts</h1><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <p>An Artifact is &#x201c;anything&#x201d; (any file) that can be addressed using its coordinates, and Maven downloads, installs or deploys for you. Most of them are POMs and JARs but an artifact can be really anything. A very important thing about artifacts is that they have coordinates, so they are not &#x201c;just files&#x201d;, but they are files that are in some way addressable by Maven.</p> <p>Artifact coordinates, are most often represented as <code>groupId:artifactId:version</code>, or GAV in short or when informally used (please note that Artifact coordinates has more fields, but for brevity we still call the coordinates &#x201c;GAV&#x201d;, not &#x201c;GAVCE&#x201d;). The artifact coordinates uniquely describe the artifact you are referring to, but does not tell anything about its source (or origin). It is up to Maven to figure out (or you to tell Maven how to figure it out).</p> <p>A word about uniqueness: as stated above, GAV coordinates uniquely identifies artifact, but only <strong>within one repository</strong>. It is clearly possible (but discouraged) to have multiple repositories with overlapping content (so R1 and R2 both contain artifact with same GAV). If those files are not-identical (truly, ie. hash wise), it may cause severe issues without you noticing it. In short, these cases should be avoided.</p> <p>While Maven internally uses the notion of &#x201c;artifact&#x201d; thoroughly (just look at sources!), end users may never hit this term. That's due the fact, that while for Maven, &#x201c;everything is artifact&#x201d; (internally), Maven end users actually speak about &#x201c;projects&#x201d;, &#x201c;parent projects&#x201d;, &#x201c;dependencies&#x201d;, &#x201c;build plugins&#x201d;, &#x201c;reporting plugins&#x201d;, &#x201c;build extensions&#x201d; and so on.</p><section><a id="Artifact_Properties"></a> <h2>Artifact Properties</h2> <p>The artifacts that Maven (internally) uses has following (for our topic related) properties:</p> <table class="table table-striped"> <thead> <tr class="a"> <th>Name</th> <th>Description</th></tr></thead><tbody> <tr class="b"> <td>groupId</td> <td>The artifact group</td></tr> <tr class="a"> <td>artifactId</td> <td>The artifact id</td></tr> <tr class="b"> <td>version</td> <td>The artifact version (linked w/ baseVersion)</td></tr> <tr class="a"> <td>baseVersion</td> <td>The artifact base version (linked w/ version)</td></tr> <tr class="b"> <td>classifier</td> <td>The artifact distinguishing classifier (optional)</td></tr> <tr class="a"> <td>extension</td> <td>The artifact extension (default: &#x201c;jar&#x201d;)</td></tr></tbody> </table> <p>One property worth explaining is a bit of special one: <code>baseVersion</code> that is actually derived/linked to <code>version</code> (or the other way around, depending on the context): for release artifacts, it holds the same value as <code>version</code>, whereas for snapshot artifacts, it holds the &#x201c;non-timestamped snapshot version&#x201d;. For example, for snapshot version &#x201c;1.0-20220119.164608-1&#x201d;, the <code>baseVersion</code> would have the value &#x201c;1.0-SNAPSHOT&#x201d;. So, <code>version</code> and <code>baseVersion</code> are linked, derived from each other, but <strong>they have different values only in case of snapshots</strong>.</p> <p>Important note about Artifacts: the fact is an artifact a snapshot or not, should be queried with method <code>Artifact#isSnapshot()</code>.</p></section><section><a id="But_where_do_I_set_Artifact_extension.3F"></a> <h2>But where do I set Artifact extension?</h2> <p>In short, nowhere. Or maybe &#x201c;you rarely have to&#x201d;. Maven POM (where you declare your project, parent project, dependencies, plugins and other), maps those elements onto artifact coordinates with some extra logic.</p> <p>In case of &#x201c;project&#x201d; and &#x201c;parent project&#x201d; aka POMs (after POM made into effective POM, ie. parent values inherited):</p> <table class="table table-striped"> <thead> <tr class="a"> <th>Artifact Property</th> <th>Project POM (pom.xml)</th> <th>POM Artifact</th></tr></thead><tbody> <tr class="b"> <td>groupId</td> <td><code>project/groupId</code></td> <td>-&gt; groupId</td></tr> <tr class="a"> <td>artifactId</td> <td><code>project/artifactId</code></td> <td>-&gt; artifactId</td></tr> <tr class="b"> <td>version</td> <td><code>project/version</code></td> <td>-&gt; version</td></tr> <tr class="a"> <td>classifier</td> <td>-</td> <td>&quot;&quot; (always)</td></tr> <tr class="b"> <td>extension</td> <td>-</td> <td><code>pom</code> (always)</td></tr></tbody> </table> <p>In case of &#x201c;build plugins&#x201d; and &#x201c;build extensions&#x201d;, as they are JARs, this is how corresponding elements are mapped (for build extension change the XML path prefix to <code>project/build/extensions/extension[x]</code>):</p> <table class="table table-striped"> <thead> <tr class="a"> <th>Artifact Property</th> <th>Plugin in Project POM</th> <th>Plugin/Extension Artifact</th></tr></thead><tbody> <tr class="b"> <td>groupId</td> <td><code>project/build/plugins/plugin[x]/groupId</code></td> <td>-&gt; groupId</td></tr> <tr class="a"> <td>artifactId</td> <td><code>project/build/plugins/plugin[x]/artifactId</code></td> <td>-&gt; artifactId</td></tr> <tr class="b"> <td>version</td> <td><code>project/build/plugins/plugin[x]/version</code></td> <td>-&gt; version</td></tr> <tr class="a"> <td>classifier</td> <td>-</td> <td>-&gt; &quot;&quot; (always)</td></tr> <tr class="b"> <td>extension</td> <td>-</td> <td>-&gt; <code>jar</code> (always)</td></tr></tbody> </table> <p>And finally, in case of &#x201c;dependencies&#x201d;, this is the mapping (no, scope is NOT part of artifact coordinates):</p> <table class="table table-striped"> <thead> <tr class="a"> <th>Artifact Property</th> <th>Dependency in Project POM</th> <th>Dependency Artifact</th></tr></thead><tbody> <tr class="b"> <td>groupId</td> <td><code>project/dependencies/dependency[x]/groupId</code></td> <td>-&gt; groupId</td></tr> <tr class="a"> <td>artifactId</td> <td><code>project/dependencies/dependency[x]/artifactId</code></td> <td>-&gt; artifactId</td></tr> <tr class="b"> <td>version</td> <td><code>project/dependencies/dependency[x]/version</code></td> <td>-&gt; version</td></tr> <tr class="a"> <td>classifier</td> <td><code>project/dependencies/dependency[x]/classifier</code></td> <td>-&gt; classifier</td></tr> <tr class="b"> <td>extension</td> <td><code>project/dependencies/dependency[x]/type</code></td> <td>-&gt; type handler provided, or same as type</td></tr></tbody> </table> <p>Here, we need to make a short detour to explain &#x201c;type&#x201d; (of a dependency) and how it becomes artifact extension.</p> <p>Maven for dependencies defines &#x201c;type&#x201d;, that describes what that dependency is (should it be added to classpath and many other things). Plugins and extensions may define new types, that is usually a must for plugins introducing a &#x201c;packaging&#x201d; (lifecycle mapping) by providing <code>ArtifactHandler</code> components with name corresponding to type name.</p> <p>Maven Core out of the box <a href="/ref/current/maven-core/artifact-handlers.html">defines following &#x201c;types&#x201d; (handled by same named <code>ArtifactHandler</code> components)</a>:</p> <table class="table table-striped"> <thead> <tr class="a"> <th>Type Name</th> <th>Extension</th> <th>Classifier</th></tr></thead><tbody> <tr class="b"> <td>pom</td> <td><code>pom</code></td> <td> </td></tr> <tr class="a"> <td>jar</td> <td><code>jar</code></td> <td> </td></tr> <tr class="b"> <td>maven-plugin</td> <td><code>jar</code></td> <td> </td></tr> <tr class="a"> <td>ear</td> <td><code>ear</code></td> <td> </td></tr> <tr class="b"> <td>ejb</td> <td><code>jar</code></td> <td> </td></tr> <tr class="a"> <td>ejb-client</td> <td><code>jar</code></td> <td><code>ejb-client</code></td></tr> <tr class="b"> <td>javadoc</td> <td><code>jar</code></td> <td><code>javadoc</code></td></tr> <tr class="a"> <td>java-source</td> <td><code>jar</code></td> <td><code>sources</code></td></tr> <tr class="b"> <td>rar</td> <td><code>rar</code></td> <td> </td></tr> <tr class="a"> <td>test-jar</td> <td><code>jar</code></td> <td><code>tests</code></td></tr> <tr class="b"> <td>war</td> <td><code>war</code></td> <td> </td></tr> <tr class="a"> <td><strong>any</strong></td> <td>any</td> <td> </td></tr></tbody> </table> <p>From table above, we can see that if we define the dependency type as &#x201c;war&#x201d;, we will hit the &#x201c;war&#x201d; handler, that will result in using the <code>war</code> extension (which may not be obvious, as the type and extension we end up with are the same, but internally this indirection does happen). The &#x201c;test-jar&#x201d; is more obvious, as it translates to <code>jar</code> extension. Finally, the <strong>any</strong> last row will be used if none above matches, hence in that case your &#x201c;type&#x201d; is used just as &#x201c;extension&#x201d;, for example you can write <code>&lt;type&gt;tar.gz&lt;/type&gt;</code> for dependency, and you will end up with extension <code>tar.gz</code> (all this happens because as there is no artifact handler named &#x201c;tar.gz&#x201d; in table above). Still, you should be aware that this table above may be extended by various plugins and extensions you use in your build!</p> <p>Also, this has &#x201c;interesting&#x201d; consequences, consider for example following Artifact: <code>org.project:reusable-test-support:1.0:tests:jar</code>. With type handlers above, maybe surprisingly, the dependency to this very same artifact can be described in two ways:</p> <pre class="prettyprint linenums"><code class="language-xml">&lt;dependency&gt; &lt;groupId&gt;org.project&lt;/groupId&gt; &lt;artifactId&gt;reusable-test-support&lt;/artifactId&gt; &lt;version&gt;1.0&lt;/version&gt; &lt;classifier&gt;tests&lt;/classifier&gt; &lt;/dependency&gt; </code></pre> <p>and the equivalent dependency would be:</p> <pre class="prettyprint linenums"><code class="language-xml">&lt;dependency&gt; &lt;groupId&gt;org.project&lt;/groupId&gt; &lt;artifactId&gt;reusable-test-support&lt;/artifactId&gt; &lt;version&gt;1.0&lt;/version&gt; &lt;type&gt;test-jar&lt;/type&gt; &lt;/dependency&gt; </code></pre> <p>Obvious difference is presence of <code>classifier</code> in first case, while in second lack of it but presence of <code>type</code> &#x201c;test-jar&#x201d;, that in the other hand, implies classifier of &#x201c;tests&#x201d;. In both cases, extension is &#x201c;jar&#x201d; (in first it uses the default value for this property, while in second type defines it).</p> <p>Note: In this very case, using the first way is somewhat &#x201c;explicit&#x201d;, and is recommended way. Not so for the cases when type handler carries some important extra information (like some custom packaging), where using <code>type</code> is more appropriate. Simply put, in this case the type &#x201c;test-jar&#x201d; is like an alias for ordinary JARs with &#x201c;tests&#x201d; classifier.</p></section><section><a id="Summary"></a> <h2>Summary</h2> <p>In short, this is how various Maven bits like &#x201c;project&#x201d;, &#x201c;parent project&#x201d;, &#x201c;plugin&#x201d;, &#x201c;extension&#x201d; and &#x201c;dependency&#x201d; have artifact coordinates mapped from POM elements. Using this knowledge, we can always deduce the artifact coordinate of these POM elements.</p></section></section> </main> </div> </div> <hr/> <footer> <div class="container-fluid"> <div class="row-fluid"> <p>© 2002–2024 <a href="https://www.apache.org/">The Apache Software Foundation</a> </p> </div> </div> </footer> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10