src.site.apt.usage.apt Maven / Gradle / Ivy
~~ 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.
------
Usage
------
Allan Ramirez
Brian Fox
------
Mar 2007
------
Usage
Brief examples on how to use the dependency goals.
* Generic Plugin configuration information
See the following links for information about including and configuring plugins in your project:
*{{{http://maven.apache.org/guides/mini/guide-configuring-plugins.html}Configuring Plugins}}
*{{{http://maven.apache.org/guides/plugin/guide-java-plugin-development.html}Plugin Development}}
*{{{http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html}Plugin Prefix}}
* The <<>> mojo
This goal is meant to be bound to a lifecycle phase and configured in your
<<>>. It will resolve the artifact from the repository and place a copy
in the specified location. Multiple artifacts can be defined in a single
execution. A default output directory is specified but can be overriden for
each ArtifactItem by setting the optional outputDirectory field. An
optional new name can be set to rename or the version stripped while copying.
The artifact version is optional. If not set, the plugin will attempt to resolve it from the
project dependencies and then the dependencyManagement section.
See the {{#Overwrite Rules}} section for rules about how overwriting is handled.
[]
Configure the plugin something like this if you intend to bind it to execute along with your build:
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
copy
package
copy
[ groupId ]
[ artifactId ]
[ version ]
[ packaging ]
[ true or false ]
[ output directory ]
[ filename ]
[...]
+---+
If you intend to configure this mojo for execution on the command line using:
+---+
mvn dependency:copy
+---+
you must not put the configuration inside the tag. Your configuration should look like this:
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
[ groupId ]
[ artifactId ]
[ version ]
[ packaging ]
[ true or false ]
[ output directory ]
[ filename ]
[...]
+---+
* The <<>> mojo
This goal can be bound to a lifecycle phase and configured in your <<>>.
It will resolve the dependencies (including transitive dependencies) from
the repository and place a copy in the specified location.
The artifacts can be placed in subfolders based on type. For example:
\outputDirectory
\outputDirectory\jars
\outputDirectory\wars
The artifacts can be placed in a subfolder per artifact. For example:
\outputDirectory\junit-junit-3.8.1\
This feature also works with the subfolders per type. For example:
\outputDirectory\jars\junit-junit-3.8.1\
Artifacts can also be resolved by specifying the classifer and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifer and type. For example:
<<>> will try to find
the sources for all dependencies and copy them.
Also included is the ability to include or exclude by type (war, jar etc), scope (runtime, test, etc), classifier (jdk14, sources, etc), groupId, artifactId, or a combination of them. NOTE: If you mix includes and excludes of the same category (ie scope), then only the includes will be used.
See the {{#Overwrite Rules}} section for rules about how overwriting is handled.
The goal can also be launched from the command line like:
<<>>
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
copy-dependencies
package
copy-dependencies
[...]
+---+
* The <<>> mojo
This goal is meant to be bound to a lifecycle and configured in your pom.xml.
It will resolve the artifact from the repository and place a copy in the
specified location. Multiple artifacts can be defined in a single execution.
A default outputDirectory is specified but can be overriden for each
ArtifactItem by setting the optional outputDirectory field.
See the {{#Overwrite Rules}} section for rules about how overwriting is handled.
The artifact version is optional. If not set, the plugin will attempt to resolve it from the
project dependencies and then the dependencyManagement section.
Configure the plugin something like this if you intend to bind it to execute along with your build:
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
unpack
package
unpack
[...]
+---+
If you intend to configure this mojo for execution on the command line using:
+---+
mvn dependency:unpack
+---+
you must not put the configuration inside the tag. Your configuration should look like this:
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
[ groupId ]
[ artifactId ]
[ version ]
[ packaging ]
[ true or false ]
[ output directory ]
[ filename ]
[...]
+---+
* The <<>> mojo
This goal can be bound to a lifecycle and configured in your pom.xml.
It will resolve the dependencies (including transitive dependencies) from
the repository and unpack them to the specified location.
Unpack-dependencies includes transitive dependencies by default. To include
only direct dependencies, set the excludeTransitive parameter to true.
Dependencies can be included or excluded by a list of types. See
{{{unpack-dependencies-mojo.html}unpack-dependencies}} for details.
The artifacts can be unpacked in subfolders based on type. For example:
\outputDirectory
\outputDirectory\jars
\outputDirectory\wars
The artifacts can be placed in a subfolder per artifact. For example:
\outputDirectory\junit-junit-3.8.1\
This feature also works with the subfolders per type. For example:
\outputDirectory\jars\junit-junit-3.8.1\
Artifacts can also be resolved by specifying the classifer and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifer and type. For example:
<<>> will try to find
the sources for all dependencies and unpack them.
Also included is the ability to include or exclude by type (war, jar etc), scope (runtime, test, etc), classifier (jdk14, sources, etc), groupId, artifactId, or a combination of them. NOTE: If you mix includes and excludes of the same category (ie scope), then only the includes will be used.
See the {{#Overwrite Rules}} section for rules about how overwriting is handled.
The goal can also be launched from the command line like:
<<>>
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
unpack-dependencies
package
unpack-dependencies
[...]
+---+
* {Overwrite Rules}
Artifacts are copied or unpacked using the following rules:
* If the artifact doesn't exist in the destination, then copy/unpack it.
Otherwise:
* For copy/unpack mojo only: if <<>> or <<>> is true, then it will force an overwrite.
* Releases check the <<>> value (default = false). If true, then it will force an overwrite.
* Snapshots check the <<>> value (default = false). If true, then it will force an overwrite.
* If none of the above is set to true, then it defaults to the <<>> value (default = true). This value, if true, causes
the plugin to only copy if the source is newer than the destination (or it doesn't exist in the destination). (for unpack, this checks the existence of the marker file, created in the <<>> path.
To avoid unexpected behavior after <<>>, this path should normally be contained within the <<>> hierarchy.)
Examples:
* Using the default settings (<<>> = false, <<>> = false, <<>> = true), then a release or snapshot artifact will
only over write the destination if the source is newer than the destination (or marker file if unpacking).
* If <<>> = true, then a release artifact (ie <<>>) will always overwrite.
* If <<>> = true, then a snapshot artifact (ie <<>>) will always overwrite.
* If all of the values are false, then a copy/unpack will only occur if it doesn't exist in the destination (or <<>> if unpacking).
* The <<>> mojo
Resolve is intended to be used from the command line like:
<<>>
This goal simply tells maven to resolve all test scope (includes compile)
dependencies and then displays the resolved versions. This is intended to
help ensure all dependencies are downloaded to the local repository. This is
usefull when troubleshooting or during intermittent remote repository
failures when repeatedly building multiproject modules is undersirable and
the build is failing on dependency resolution. It can also be used to quickly
determine how versions are being resolved.
Artifacts can also be resolved by specifying the classifer and optionally
type. Type is only used with the classifier and defaults to java-sources.
When the classifier is set, the list of dependencies is used as the base to
resolve artifacts with the classifer and type. For example:
<<>> will try to find the
test-jar for all dependencies resolve them to the local repository.
* The <<>> mojo
Sources is intended to be used from the command line like:
<<>>
This is the same as the resolve goal except it includes the source
attachments if they exist. This is useful when you want the source
attachments downloaded to your local repository and
you don't want to use the eclipse plugin to do this since the eclipse plugin
creates/overwrites the eclipse files.
You can also define the <<>> either in the pom or settings
to be a common location for all projects. This allows the system to resolve sources faster for dependencies that don't
have the sources published. The plugin will store a marker file to describe if the sources where resolved or not. By placing
them in a common location, multiple attempts to resolve non-existent sources will be avoided.
* The <<>> mojo
Resolve-plugins is intended to be used from the command line like:
<<>>
This is the same as the resolve goal except it resolves plugins and
optionally their dependencies.
* The <<>> mojo
This goal is exactly the same as calling
<<>>.
* The <<>> mojo
This goal is meant to delete all of the dependencies for the current project
(or projects, in the case of a multimodule build) from the local repository.
Purges can be run with a variety of limiting parameters, including artifact
exclusions, limiting to direct dependencies only, and different levels of
depth for deletion. By default, deleted artifacts can be re-resolved
afterwards; you can disable this by specifying <<<-DreResolve=false>>>.
In its simplest form, the mojo can be called like this:
+---+
mvn dependency:purge-local-repository
+---+
To add the restriction that the <<>>
artifact not be deleted, we can modify the command to this:
+---+
mvn dependency:purge-local-repository -Dexclude=org.apache.maven:maven-plugin-api
+---+
<> The <<>> parameter is a comma-delimited list of
groupId:artifactId pairs. It has a corresponding List-based parameter -
<<>> - for convenient use inside the POM.
Another handy aspect of this mojo is the ability to wipe out artifacts at
varying depths. These depths are:
* <> - Delete just the artifact's file.
* <> - Delete the version directory containing this artifact. Amounts to
<<>>.
* <> - Delete the artifactId directory containing this artifact.
Amounts to <<>>.
* <> - Delete the groupId directory structure containing this artifact.
At a minimum, this amounts to <<>>.
However, if the groupId contains multiple parts, the mojo will prune all groupId-part
directories that contain only the files associated with this artifact. Again, note that
the exception to this pruning algorithm is the lowest groupId part, which will always
be pruned.
[]
To prune dependency artifacts back to their associated artifactId directories
(in order to verify proper artifact resolution, for example), simply use this
command:
+---+
mvn dependency:prune-local-repository -DresolutionFuzziness=artifactId
+---+
Finally, it's possible to bind this mojo to the build lifecycle. One reason for this
might be to clean out all dependencies when the build is initialized, to verify
correct resolution.
* The <<>> mojo
Since: 2.0-alpha-2
This goal will output a classpath string of dependencies from the local repository to a file or log. For instance, the file would contain a classpath string like this:
+---+
/home/foo/.m2/repository/org/java/utils/util/util-1.0.jar:/home/foo/.m2/ ....
+---+
The resulting file could then be used like this:
+---+
java -cp `cat resultFile` MyClass
+---+
In its simplest form, to output the classpath to the log, the mojo can be called like this:
+---+
mvn dependency:build-classpath
+---+
or to write the classpath to cp.txt.:
+---+
mvn dependency:build-classpath -Dmaven.dep.cpFile=cp.txt
+---+
The goal can also be bound to a lifecycle phase with the following configuration:
+---+
[...]
org.apache.maven.plugins
maven-dependency-plugin
build-classpath
generate-sources
build-classpath
[...]
+---+
* The <<>> mojo
This mojo can be executed from the command line:
+---+
mvn dependency:analyze
+---+
This mojo also performs the checks described in the analyze-dep-mht section.
Sample output:
+---+
[INFO] [dependency:analyze]
[INFO] Used declared dependencies:
[INFO] org.codehaus.plexus:plexus-archiver:jar:1.0-alpha-7:compile
[INFO] junit:junit:jar:3.8.1:test
[INFO] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile
[INFO] org.apache.maven:maven-model:jar:2.0.5:compile
[INFO] org.apache.maven:maven-project:jar:2.0.5:compile
[INFO] org.apache.maven.shared:file-management:jar:1.1:compile
[INFO] org.codehaus.plexus:plexus-utils:jar:1.1:compile
[INFO] org.apache.maven:maven-artifact:jar:2.0.5:compile
[INFO] org.apache.maven:maven-plugin-api:jar:2.0.5:compile
[INFO] org.apache.maven.shared:maven-plugin-testing-harness:jar:1.0-beta-1:test
[INFO] org.apache.maven.shared:maven-dependency-analyzer:jar:1.0-SNAPSHOT:compile
[INFO] Used undeclared dependencies:
[INFO] None
[INFO] Unused declared dependencies:
[INFO] None
+---+
* The <<>> mojo
This mojo looks at the dependencies after final resolution and looks for mismatches in your dependencyManagement section.
In versions of maven prior to 2.0.6, it was possible to inherit versions that didn't match your dependencyManagement. See {{{http://jira.codehaus.org/browse/MNG-1577}MNG-1577}} for more info.
If this mojo detects issues, you should attempt to resolve the discrepancies before upgrading to 2.0.6 to avoid any surprises. This can be done by upgrading or downgrading the version in dependencyManagement to match what is actually
being included at runtime, or you can specify a dependency in your project to override what is being included. You can check the results by rerunning this mojo.
If you decide to override by using a dependency, be sure to note it so you can remove it later after upgrading to 2.0.6. You could also use the dependency:analyze mojo to uncover this unused direct dependency.
This mojo is also usefull for just detecting projects that override the dependencyManagement directly. Set ignoreDirect to false to detect these otherwise normal conditions.
NOTE: In 2.0-alpha-3, the Labels shown in the output are reversed. This is corrected in 2.0-alpha-4: See MDEP-78.
This mojo can be executed from the command line:
+---+
mvn dependency:analyze-dep-mgt
+---+
Sample output:
+---+
[INFO] Found Resolved Dependency / DependencyManagement mismatches:
[INFO] Dependency: commons-lang:commons-lang:jar
[INFO] DepMgt : 1.0
[INFO] Resolved: 2.3
[INFO] Dependency: commons-digester:commons-digester:jar
[INFO] DepMgt : 1.6
[INFO] Resolved: 1.7
[INFO] Dependency: javax.servlet:servlet-api:jar
[INFO] DepMgt : 2.3
[INFO] Resolved: 2.4
[WARNING] Potential problems found in Dependency Management
+---+
© 2015 - 2024 Weber Informatics LLC | Privacy Policy