Sharing Artifacts Through the Local Maven Repository
Figure 3-1 illustrates
the dependencies between the subproject, and from this
diagram, you can see that the web
subproject depends upon the core
subproject. How do you share artifacts between projects in Maven?
How do I do that?
You do this through the local Maven repository, which was
introduced in Section
1.1. The core
build will
publish its JAR to the repository and the web
build will define a dependency on the
core
JAR.
To refresh your memory, your local repository resides in
~/.maven/repository on Unix, or
%USERPROFILE%\.maven\repository
on Windows. Publishing a JAR to your local repository is as simple as
executing the jar:install
goal:
C:\dev\mavenbook\code\qotd\core>maven jar:install
_ _ _ _ | \/ |_ _ _Apache_ _ _ _ _ | |\/| / _` \ V / -_) ' \ ~ intelligent projects ~ |_| |_\_ _,_|\_/\_ _ _|_||_| v. 1.0.2 build:start: java:prepare-filesystem: [mkdir] Created dir: C:\dev\mavenbook\code\qotd\core\target\classes java:compile: [echo] Compiling to C:\dev\mavenbook\code\qotd\core/target/classes [javac] Compiling 1 source file to C:\dev\mavenbook\code\qotd\core\target\classes java:jar-resources: test:prepare-filesystem: [mkdir] Created dir: C:\dev\mavenbook\code\qotd\core\target\test-classes [mkdir] Created dir: C:\dev\mavenbook\code\qotd\core\target\test-reports test:test-resources: test:compile: [javac] Compiling 1 source file to C:\dev\mavenbook\code\qotd\core\target\test-classes test:test: [junit] Testsuite: mdn.qotd.core.QuoteGeneratorTest ...
Get Maven: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.