Dependencies in Maven #194
pwgit-create
announced in
Learning Materials
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Dependency vs Plugin
When working with Maven projects, you might encounter dependencies defined both directly within
<dependencies>tags and within plugins (like build plugins) inpom.xml. There are important differencesbetween these two approaches:
Scope of Dependencies:
<dependencies>tags: These dependencies are typically project dependencies that your applicationcode will use at runtime or compile time. They can be used by the main classes and other modules of your project.
(compilation, testing, packaging, etc.). They won't be available to your application's runtime classpath unless
you explicitly configure them to be.
Classpath Usage:
<dependencies>: These are added to the project's compile and runtime classpath.by the plugin during the build process.
Transitive Dependencies:
<dependencies>: Maven will resolve transitive dependencies for you when you declare them in thissection.
<dependencies>, Maven will also manage transitive dependencies, butthese are again scoped only to the plugin's execution context.
Lifecycle Phases:
<dependencies>: These are available throughout all phases of the build lifecycle (compile, test,package, install, deploy).
are configured for in a plugin.
Examples:
Best Practices:
build process.
<dependencies>tag.When a plugin dependency is added to the artifact jar.
When you configure a plugin like the
maven-javadoc-pluginin your build section, it's primarily intended to beused during the build process. However, its output (the generated Javadocs) can be included in the final artifact
or deployed separately based on how you've set up the plugin and its goals.
Here’s why this happens:
Plugin Execution: When you define a plugin with specific goals, Maven executes those goals at the
appropriate phase of the build lifecycle. For example:
In this configuration, the
maven-javadoc-pluginis set to run during thepackagephase of the build. Thegoal
jargenerates a JAR file containing the Javadocs.Attach Artifact: When you use the
jargoal with the JavaDoc plugin, it not only generates the Javadocsbut also attaches them as an additional artifact to the project's build lifecycle. This means that Maven will
package these Javadocs into a separate JAR file and include it in the build output.
Inclusion in Repository: When you deploy your artifacts (e.g., to GitHub Packages or another repository),
this attached Javadoc JAR gets included as part of the deployment process, alongside your main JAR artifact.
Classpath Independence: Even though the JavaDoc plugin dependencies are only needed for generating the
documentation and not for running the application, their output (the generated Javadocs) can still be packaged and
deployed separately.
So to summarize:
maven-javadoc-plugin.Packages or other repositories.
If you look at the Maven documentation or your specific plugin configuration, you'll see that the
jargoal isresponsible for creating this separate Javadoc JAR file:
This is what allows the generated JavaDocs to be included in the deployment output.
Beta Was this translation helpful? Give feedback.
All reactions