summaryrefslogtreecommitdiff
path: root/static/passthrough/20250609-maven-primer.txt
blob: 9d438a0fff6c0412f33cadc87b137a5fb51e4514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Maven
A beginner's guide

https://maven.apache.org
"Apache Maven is a software project management
and comprehension tool"

Based on a "project object model (POM)"
that allows Maven to build the project as configured

Through its configuration, you can tell Maven:
- What your project dependencies are
- How to compile your project
- How to package your project
- How to run your unit tests
- How to... whatever, really

Maven is architected around plugins.
Its functionnalities can be extended by writing new plugins.
Though, most likely a plugin already exists for your needs.

Maven is launched through the command line
with its command and a target "phase".
$ mvn deploy

When Maven runs, it follows a "lifecycle".
A lifecycle is made of "phases".
Maven will run all the phases up to the
one you specified on the command line.

Default lifecycle
- validate
- compile
- test
- package
- verify
- install
- deploy

Each build phase is made up of plugin goals.
You configure which plugins run at each phase
through Maven's config file "pom.xml".

The POM file should be in the directory from
which you invoke Maven.

The POM file specifies:
- The project's dependencies
- The plugins to use for the build

The dependencies and the plugins are called
artifacts.
They're identified by a group, a name, and
a version.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.14.0</version>
</plugin>

Maven downloads artifacts from a "repository".
There are 2 types of repositories.

Local repository
A directory on your computer.
Maven caches remote downloads
in the local repository

Remote repository
Any other repository is a remote repository.
It can be a directory, an HTTP server, ...

By default, Maven uses the following remote repository
https://repo.maven.apache.org/maven2/

Through the POM file, you can configure one
or several repositories to use.

You can instruct Maven to "deploy" your locally built 
artifact to a repository, so that other users can
instruct Maven to depend on it for their build.