Model for Maven POM (Project Object Model)
npx @tessl/cli install tessl/maven-org-apache-maven--maven-model@3.9.00
# Maven Model
1
2
A comprehensive Java library providing the core object model for Maven POM (Project Object Model) files. Maven Model defines the structure and data types used to represent Maven projects, enabling parsing, validation, and manipulation of project definitions consistently across the entire Maven build system.
3
4
## Package Information
5
6
- **Package Name**: org.apache.maven:maven-model
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add dependency to `pom.xml`:
10
11
```xml
12
<dependency>
13
<groupId>org.apache.maven</groupId>
14
<artifactId>maven-model</artifactId>
15
<version>3.9.11</version>
16
</dependency>
17
```
18
19
## Core Imports
20
21
```java
22
import org.apache.maven.model.Model;
23
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
24
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
25
import org.apache.maven.model.merge.ModelMerger;
26
```
27
28
## Basic Usage
29
30
```java
31
import org.apache.maven.model.Model;
32
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
33
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
34
import java.io.FileReader;
35
import java.io.FileWriter;
36
37
// Reading a POM file
38
MavenXpp3Reader reader = new MavenXpp3Reader();
39
Model model = reader.read(new FileReader("pom.xml"));
40
41
// Accessing model data
42
String groupId = model.getGroupId();
43
String artifactId = model.getArtifactId();
44
String version = model.getVersion();
45
List<Dependency> dependencies = model.getDependencies();
46
47
// Writing a POM file
48
MavenXpp3Writer writer = new MavenXpp3Writer();
49
writer.write(new FileWriter("output.xml"), model);
50
51
// Creating a new model programmatically
52
Model newModel = new Model();
53
newModel.setModelVersion("4.0.0");
54
newModel.setGroupId("com.example");
55
newModel.setArtifactId("my-project");
56
newModel.setVersion("1.0.0");
57
```
58
59
## Architecture
60
61
The Maven Model is built around a hierarchical object structure that mirrors the XML structure of Maven POM files:
62
63
- **Model**: Root container representing the entire project definition
64
- **ModelBase**: Shared foundation for Model and Profile containing common build elements
65
- **Generated Classes**: 40+ POJOs generated from Modello MDO definitions representing all POM elements
66
- **I/O Layer**: XML readers and writers for serialization with location tracking support
67
- **Merging System**: Sophisticated inheritance and profile merging through ModelMerger
68
69
This design enables Maven to consistently parse, validate, manipulate, and generate POM files across all Maven tools and plugins while maintaining full fidelity to the original XML structure and supporting advanced features like inheritance, profiles, and error location tracking.
70
71
## Capabilities
72
73
### Core Model Classes
74
75
The main Model class and fundamental structure classes that represent the root POM elements and shared build configuration.
76
77
```java { .api }
78
public class Model extends ModelBase {
79
public String getModelVersion();
80
public void setModelVersion(String modelVersion);
81
public Parent getParent();
82
public void setParent(Parent parent);
83
public String getGroupId();
84
public void setGroupId(String groupId);
85
public String getArtifactId();
86
public void setArtifactId(String artifactId);
87
public String getVersion();
88
public void setVersion(String version);
89
public String getPackaging();
90
public void setPackaging(String packaging);
91
public String getName();
92
public void setName(String name);
93
public String getDescription();
94
public void setDescription(String description);
95
}
96
```
97
98
[Core Model Classes](./core-model.md)
99
100
### Dependency Management
101
102
Classes for managing project dependencies, dependency scopes, exclusions, and dependency management sections.
103
104
```java { .api }
105
public class Dependency {
106
public String getGroupId();
107
public String getArtifactId();
108
public String getVersion();
109
public String getScope();
110
public String getType();
111
public String getClassifier();
112
public List<Exclusion> getExclusions();
113
public boolean isOptional();
114
public String getSystemPath();
115
}
116
```
117
118
[Dependency Management](./dependencies.md)
119
120
### Build Configuration
121
122
Build-related classes including Build, BuildBase, plugins, executions, and resource management.
123
124
```java { .api }
125
public class Build extends BuildBase {
126
public String getSourceDirectory();
127
public String getScriptSourceDirectory();
128
public String getTestSourceDirectory();
129
public String getOutputDirectory();
130
public String getTestOutputDirectory();
131
public String getDirectory();
132
public String getFinalName();
133
public List<String> getFilters();
134
public PluginManagement getPluginManagement();
135
}
136
```
137
138
[Build Configuration](./build-config.md)
139
140
### Repository Management
141
142
Repository and deployment configuration including repository policies, authentication, and distribution management.
143
144
```java { .api }
145
public class Repository extends RepositoryBase {
146
public RepositoryPolicy getReleases();
147
public RepositoryPolicy getSnapshots();
148
public void setReleases(RepositoryPolicy releases);
149
public void setSnapshots(RepositoryPolicy snapshots);
150
}
151
```
152
153
[Repository Management](./repositories.md)
154
155
### Profile System
156
157
Profile definitions, activation conditions, and profile-specific build configuration.
158
159
```java { .api }
160
public class Profile extends ModelBase {
161
public String getId();
162
public void setId(String id);
163
public Activation getActivation();
164
public void setActivation(Activation activation);
165
public Build getBuild();
166
public void setBuild(Build build);
167
}
168
```
169
170
[Profile System](./profiles.md)
171
172
### Project Metadata
173
174
Comprehensive classes for project metadata including organization, developers, licenses, mailing lists, SCM, and management systems.
175
176
```java { .api }
177
public class Developer extends Contributor {
178
public String getId();
179
public void setId(String id);
180
public List<String> getRoles();
181
public void setRoles(List<String> roles);
182
}
183
184
public class Scm {
185
public String getConnection();
186
public String getDeveloperConnection();
187
public String getUrl();
188
public String getTag();
189
public boolean isChildScmUrlInheritAppendPath();
190
public void setChildScmUrlInheritAppendPath(boolean value);
191
}
192
```
193
194
[Project Metadata](./project-metadata.md)
195
196
### XML I/O Operations
197
198
XML readers and writers for serializing models to and from POM files with location tracking and formatting preservation.
199
200
```java { .api }
201
public class MavenXpp3Reader {
202
public Model read(Reader reader) throws IOException, XmlPullParserException;
203
public Model read(InputStream in) throws IOException, XmlPullParserException;
204
public Model read(Reader reader, boolean strict) throws IOException, XmlPullParserException;
205
public Model read(InputStream in, boolean strict) throws IOException, XmlPullParserException;
206
}
207
```
208
209
[XML I/O Operations](./xml-io.md)
210
211
### Model Merging
212
213
Model inheritance and merging capabilities for parent-child POM relationships and profile integration.
214
215
```java { .api }
216
public class ModelMerger {
217
public void merge(Model target, Model source, boolean sourceDominant, Map<?, ?> hints);
218
public void mergeModel(Model target, Model source, boolean sourceDominant, Map<?, ?> hints);
219
public void mergeModelBase(ModelBase target, ModelBase source, boolean sourceDominant, Map<?, ?> hints);
220
}
221
```
222
223
[Model Merging](./model-merging.md)
224
225
### Utility Classes
226
227
Supporting classes including build extensions, file sets with pattern matching, and location tracking interfaces.
228
229
```java { .api }
230
public class Extension {
231
public String getGroupId();
232
public String getArtifactId();
233
public String getVersion();
234
}
235
236
public class FileSet extends PatternSet {
237
public String getDirectory();
238
public List<String> getIncludes();
239
public List<String> getExcludes();
240
}
241
242
public interface InputLocationTracker {
243
InputLocation getLocation(Object key);
244
void setLocation(Object key, InputLocation location);
245
}
246
```
247
248
[Utility Classes](./utility-classes.md)
249
250
## Types
251
252
### Location Tracking
253
254
```java { .api }
255
public class InputLocation {
256
public int getLineNumber();
257
public int getColumnNumber();
258
public InputSource getSource();
259
public Map<Object, InputLocation> getLocations();
260
}
261
262
public class InputSource {
263
public String getLocation();
264
public String getModelId();
265
}
266
```