0
# Repository Operations
1
2
Legacy repository system providing artifact deployment, installation, resolution, and repository management for Maven2 compatibility.
3
4
## Capabilities
5
6
### ArtifactDeployer
7
8
Interface for deploying artifacts to remote repositories.
9
10
```java { .api }
11
/**
12
* Interface for deploying artifacts to remote repositories
13
*/
14
public interface ArtifactDeployer {
15
/**
16
* Role constant for Plexus component lookup
17
*/
18
String ROLE = ArtifactDeployer.class.getName();
19
20
/**
21
* Deploys an artifact to a remote repository
22
* @param source source file to deploy
23
* @param artifact artifact metadata
24
* @param deploymentRepository target repository for deployment
25
* @param localRepository local repository reference
26
* @throws ArtifactDeploymentException if deployment fails
27
*/
28
void deploy(File source, Artifact artifact, ArtifactRepository deploymentRepository,
29
ArtifactRepository localRepository) throws ArtifactDeploymentException;
30
31
/**
32
* Deploys an artifact using basedir and final name (deprecated)
33
* @param basedir base directory path
34
* @param finalName final name of the artifact
35
* @param artifact artifact metadata
36
* @param deploymentRepository target repository
37
* @param localRepository local repository reference
38
* @throws ArtifactDeploymentException if deployment fails
39
* @deprecated Use deploy(File, Artifact, ArtifactRepository, ArtifactRepository) instead
40
*/
41
@Deprecated
42
void deploy(String basedir, String finalName, Artifact artifact,
43
ArtifactRepository deploymentRepository, ArtifactRepository localRepository)
44
throws ArtifactDeploymentException;
45
}
46
```
47
48
### DefaultArtifactDeployer
49
50
Default implementation of ArtifactDeployer.
51
52
```java { .api }
53
/**
54
* Default implementation of ArtifactDeployer
55
*/
56
public class DefaultArtifactDeployer extends AbstractLogEnabled implements ArtifactDeployer {
57
/**
58
* Deploys an artifact to a remote repository
59
*/
60
public void deploy(File source, Artifact artifact, ArtifactRepository deploymentRepository,
61
ArtifactRepository localRepository) throws ArtifactDeploymentException;
62
}
63
```
64
65
### ArtifactInstaller
66
67
Interface for installing artifacts to local repository.
68
69
```java { .api }
70
/**
71
* Interface for installing artifacts to local repository
72
*/
73
public interface ArtifactInstaller {
74
/**
75
* Role constant for Plexus component lookup
76
*/
77
String ROLE = ArtifactInstaller.class.getName();
78
79
/**
80
* Installs an artifact to the local repository
81
* @param source source file to install
82
* @param artifact artifact metadata
83
* @param localRepository local repository for installation
84
* @throws ArtifactInstallationException if installation fails
85
*/
86
void install(File source, Artifact artifact, ArtifactRepository localRepository)
87
throws ArtifactInstallationException;
88
89
/**
90
* Installs an artifact using basedir and final name (deprecated)
91
* @param basedir base directory path
92
* @param finalName final name of the artifact
93
* @param artifact artifact metadata
94
* @param localRepository local repository for installation
95
* @throws ArtifactInstallationException if installation fails
96
* @deprecated Use install(File, Artifact, ArtifactRepository) instead
97
*/
98
@Deprecated
99
void install(String basedir, String finalName, Artifact artifact,
100
ArtifactRepository localRepository) throws ArtifactInstallationException;
101
}
102
```
103
104
### DefaultArtifactInstaller
105
106
Default implementation of ArtifactInstaller.
107
108
```java { .api }
109
/**
110
* Default implementation of ArtifactInstaller
111
*/
112
public class DefaultArtifactInstaller extends AbstractLogEnabled implements ArtifactInstaller {
113
/**
114
* Installs an artifact to the local repository
115
*/
116
public void install(File source, Artifact artifact, ArtifactRepository localRepository)
117
throws ArtifactInstallationException;
118
}
119
```
120
121
### ArtifactResolver
122
123
Interface for artifact resolution and dependency management.
124
125
```java { .api }
126
/**
127
* Interface for artifact resolution and dependency management
128
* Most methods are deprecated in favor of newer APIs
129
*/
130
public interface ArtifactResolver {
131
/**
132
* Primary resolution method using request/response pattern
133
* @param request artifact resolution request with all parameters
134
* @return resolution result with resolved artifacts and metadata
135
*/
136
ArtifactResolutionResult resolve(ArtifactResolutionRequest request);
137
138
/**
139
* Role constant for Plexus component lookup (deprecated)
140
* @deprecated Legacy Plexus component role
141
*/
142
@Deprecated
143
String ROLE = ArtifactResolver.class.getName();
144
145
/**
146
* Resolves an artifact (deprecated)
147
* @param artifact artifact to resolve
148
* @param remoteRepositories remote repositories to search
149
* @param localRepository local repository
150
* @throws ArtifactResolutionException if resolution fails
151
* @throws ArtifactNotFoundException if artifact not found
152
* @deprecated Use resolve(ArtifactResolutionRequest) instead
153
*/
154
@Deprecated
155
void resolve(Artifact artifact, List<ArtifactRepository> remoteRepositories,
156
ArtifactRepository localRepository)
157
throws ArtifactResolutionException, ArtifactNotFoundException;
158
159
/**
160
* Resolves artifact with transfer listener (deprecated)
161
* @param artifact artifact to resolve
162
* @param remoteRepositories remote repositories to search
163
* @param localRepository local repository
164
* @param downloadMonitor transfer listener for monitoring progress
165
* @throws ArtifactResolutionException if resolution fails
166
* @throws ArtifactNotFoundException if artifact not found
167
* @deprecated Use resolve(ArtifactResolutionRequest) instead
168
*/
169
@Deprecated
170
void resolve(Artifact artifact, List<ArtifactRepository> remoteRepositories,
171
ArtifactRepository localRepository, TransferListener downloadMonitor)
172
throws ArtifactResolutionException, ArtifactNotFoundException;
173
174
/**
175
* Resolves artifact with forced resolution (deprecated)
176
* @param artifact artifact to resolve
177
* @param remoteRepositories remote repositories to search
178
* @param localRepository local repository
179
* @throws ArtifactResolutionException if resolution fails
180
* @throws ArtifactNotFoundException if artifact not found
181
* @deprecated Use resolve(ArtifactResolutionRequest) instead
182
*/
183
@Deprecated
184
void resolveAlways(Artifact artifact, List<ArtifactRepository> remoteRepositories,
185
ArtifactRepository localRepository)
186
throws ArtifactResolutionException, ArtifactNotFoundException;
187
188
/**
189
* Resolves transitively with basic parameters (deprecated)
190
* @param artifacts set of artifacts to resolve
191
* @param originatingArtifact the originating artifact
192
* @param localRepository local repository
193
* @param remoteRepositories remote repositories to search
194
* @param source metadata source
195
* @param filter artifact filter
196
* @return resolution result
197
* @throws ArtifactResolutionException if resolution fails
198
* @throws ArtifactNotFoundException if artifact not found
199
* @deprecated Use resolve(ArtifactResolutionRequest) instead
200
*/
201
@Deprecated
202
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
203
Artifact originatingArtifact,
204
ArtifactRepository localRepository,
205
List<ArtifactRepository> remoteRepositories,
206
ArtifactMetadataSource source,
207
ArtifactFilter filter)
208
throws ArtifactResolutionException, ArtifactNotFoundException;
209
210
/**
211
* Resolves transitively with managed versions (deprecated)
212
* @param artifacts set of artifacts to resolve
213
* @param originatingArtifact the originating artifact
214
* @param managedVersions managed version mappings
215
* @param localRepository local repository
216
* @param remoteRepositories remote repositories to search
217
* @param source metadata source
218
* @return resolution result
219
* @throws ArtifactResolutionException if resolution fails
220
* @throws ArtifactNotFoundException if artifact not found
221
* @deprecated Use resolve(ArtifactResolutionRequest) instead
222
*/
223
@Deprecated
224
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
225
Artifact originatingArtifact,
226
Map<String, Artifact> managedVersions,
227
ArtifactRepository localRepository,
228
List<ArtifactRepository> remoteRepositories,
229
ArtifactMetadataSource source)
230
throws ArtifactResolutionException, ArtifactNotFoundException;
231
232
/**
233
* Resolves transitively with managed versions and filter (deprecated)
234
* @param artifacts set of artifacts to resolve
235
* @param originatingArtifact the originating artifact
236
* @param managedVersions managed version mappings
237
* @param localRepository local repository
238
* @param remoteRepositories remote repositories to search
239
* @param source metadata source
240
* @param filter artifact filter
241
* @return resolution result
242
* @throws ArtifactResolutionException if resolution fails
243
* @throws ArtifactNotFoundException if artifact not found
244
* @deprecated Use resolve(ArtifactResolutionRequest) instead
245
*/
246
@Deprecated
247
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
248
Artifact originatingArtifact,
249
Map<String, Artifact> managedVersions,
250
ArtifactRepository localRepository,
251
List<ArtifactRepository> remoteRepositories,
252
ArtifactMetadataSource source,
253
ArtifactFilter filter)
254
throws ArtifactResolutionException, ArtifactNotFoundException;
255
256
/**
257
* Resolves transitively with basic parameters alternate signature (deprecated)
258
* @param artifacts set of artifacts to resolve
259
* @param originatingArtifact the originating artifact
260
* @param remoteRepositories remote repositories to search
261
* @param localRepository local repository
262
* @param source metadata source
263
* @return resolution result
264
* @throws ArtifactResolutionException if resolution fails
265
* @throws ArtifactNotFoundException if artifact not found
266
* @deprecated Use resolve(ArtifactResolutionRequest) instead
267
*/
268
@Deprecated
269
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
270
Artifact originatingArtifact,
271
List<ArtifactRepository> remoteRepositories,
272
ArtifactRepository localRepository,
273
ArtifactMetadataSource source)
274
throws ArtifactResolutionException, ArtifactNotFoundException;
275
276
/**
277
* Resolves transitively with listeners (deprecated)
278
* @param artifacts set of artifacts to resolve
279
* @param originatingArtifact the originating artifact
280
* @param managedVersions managed version mappings
281
* @param localRepository local repository
282
* @param remoteRepositories remote repositories to search
283
* @param source metadata source
284
* @param filter artifact filter
285
* @param listeners resolution listeners
286
* @return resolution result
287
* @throws ArtifactResolutionException if resolution fails
288
* @throws ArtifactNotFoundException if artifact not found
289
* @deprecated Use resolve(ArtifactResolutionRequest) instead
290
*/
291
@Deprecated
292
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
293
Artifact originatingArtifact,
294
Map<String, Artifact> managedVersions,
295
ArtifactRepository localRepository,
296
List<ArtifactRepository> remoteRepositories,
297
ArtifactMetadataSource source,
298
ArtifactFilter filter,
299
List<ResolutionListener> listeners)
300
throws ArtifactResolutionException, ArtifactNotFoundException;
301
302
/**
303
* Resolves transitively with listeners alternate signature (deprecated)
304
* @param artifacts set of artifacts to resolve
305
* @param originatingArtifact the originating artifact
306
* @param remoteRepositories remote repositories to search
307
* @param localRepository local repository
308
* @param source metadata source
309
* @param listeners resolution listeners
310
* @return resolution result
311
* @throws ArtifactResolutionException if resolution fails
312
* @throws ArtifactNotFoundException if artifact not found
313
* @deprecated Use resolve(ArtifactResolutionRequest) instead
314
*/
315
@Deprecated
316
ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts,
317
Artifact originatingArtifact,
318
List<ArtifactRepository> remoteRepositories,
319
ArtifactRepository localRepository,
320
ArtifactMetadataSource source,
321
List<ResolutionListener> listeners)
322
throws ArtifactResolutionException, ArtifactNotFoundException;
323
}
324
```
325
326
### ArtifactRepositoryFactory
327
328
Factory interface for creating and configuring artifact repositories.
329
330
```java { .api }
331
/**
332
* Factory for creating and configuring artifact repositories
333
*/
334
public interface ArtifactRepositoryFactory {
335
/**
336
* Default layout identifier
337
*/
338
String DEFAULT_LAYOUT_ID = "default";
339
340
/**
341
* Local repository identifier
342
*/
343
String LOCAL_REPOSITORY_ID = "local";
344
345
/**
346
* Creates an artifact repository
347
* @param id repository identifier
348
* @param url repository URL
349
* @param layoutId layout type identifier
350
* @param snapshots snapshot policy
351
* @param releases release policy
352
* @return configured ArtifactRepository instance
353
* @throws UnknownRepositoryLayoutException if layout is not recognized
354
*/
355
ArtifactRepository createArtifactRepository(String id, String url, String layoutId,
356
ArtifactRepositoryPolicy snapshots,
357
ArtifactRepositoryPolicy releases)
358
throws UnknownRepositoryLayoutException;
359
360
/**
361
* Creates a deployment artifact repository
362
* @param id repository identifier
363
* @param url repository URL
364
* @param layout repository layout
365
* @param uniqueVersion whether to use unique version naming
366
* @return configured ArtifactRepository for deployment
367
*/
368
ArtifactRepository createDeploymentArtifactRepository(String id, String url,
369
ArtifactRepositoryLayout layout,
370
boolean uniqueVersion);
371
372
/**
373
* Sets global update policy for snapshots
374
* @param snapshotPolicy update policy ("daily", "always", "never", etc.)
375
*/
376
void setGlobalUpdatePolicy(String snapshotPolicy);
377
}
378
```
379
380
## Usage Examples
381
382
### Artifact Deployment
383
384
```java
385
import org.apache.maven.artifact.deployer.ArtifactDeployer;
386
import org.apache.maven.artifact.deployer.DefaultArtifactDeployer;
387
import org.apache.maven.artifact.Artifact;
388
import org.apache.maven.artifact.repository.ArtifactRepository;
389
390
// Deploy an artifact to remote repository
391
ArtifactDeployer deployer = new DefaultArtifactDeployer();
392
File artifactFile = new File("target/my-artifact-1.0.jar");
393
394
try {
395
deployer.deploy(artifactFile, artifact, deploymentRepository, localRepository);
396
System.out.println("Artifact deployed successfully");
397
} catch (ArtifactDeploymentException e) {
398
System.err.println("Deployment failed: " + e.getMessage());
399
}
400
```
401
402
### Artifact Installation
403
404
```java
405
import org.apache.maven.artifact.installer.ArtifactInstaller;
406
import org.apache.maven.artifact.installer.DefaultArtifactInstaller;
407
408
// Install an artifact to local repository
409
ArtifactInstaller installer = new DefaultArtifactInstaller();
410
File artifactFile = new File("target/my-artifact-1.0.jar");
411
412
try {
413
installer.install(artifactFile, artifact, localRepository);
414
System.out.println("Artifact installed to local repository");
415
} catch (ArtifactInstallationException e) {
416
System.err.println("Installation failed: " + e.getMessage());
417
}
418
```
419
420
### Artifact Resolution
421
422
```java
423
import org.apache.maven.artifact.resolver.ArtifactResolver;
424
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
425
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
426
427
// Modern resolution approach using request/response
428
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
429
request.setArtifact(artifact);
430
request.setLocalRepository(localRepository);
431
request.setRemoteRepositories(remoteRepositories);
432
433
try {
434
ArtifactResolutionResult result = resolver.resolve(request);
435
if (result.isSuccess()) {
436
Set<Artifact> resolvedArtifacts = result.getArtifacts();
437
System.out.println("Resolved " + resolvedArtifacts.size() + " artifacts");
438
} else {
439
System.err.println("Resolution failed: " + result.getExceptions());
440
}
441
} catch (ArtifactResolutionException e) {
442
System.err.println("Resolution error: " + e.getMessage());
443
}
444
```
445
446
### Repository Creation
447
448
```java
449
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
450
import org.apache.maven.artifact.repository.ArtifactRepository;
451
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
452
453
// Create repository with policies
454
ArtifactRepositoryFactory factory = // ... get factory instance
455
ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(true, "daily", "warn");
456
ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(false, "never", "fail");
457
458
try {
459
ArtifactRepository repository = factory.createArtifactRepository(
460
"central",
461
"https://repo1.maven.org/maven2/",
462
ArtifactRepositoryFactory.DEFAULT_LAYOUT_ID,
463
snapshots,
464
releases
465
);
466
System.out.println("Repository created: " + repository.getId());
467
} catch (UnknownRepositoryLayoutException e) {
468
System.err.println("Unknown layout: " + e.getMessage());
469
}
470
```
471
472
## Required Types
473
474
### ArtifactMetadataSource
475
476
```java { .api }
477
/**
478
* Source for artifact metadata retrieval (deprecated)
479
*/
480
public interface ArtifactMetadataSource {
481
String ROLE = ArtifactMetadataSource.class.getName();
482
483
// Methods for metadata retrieval (deprecated interface)
484
}
485
```
486
487
### ArtifactFilter
488
489
```java { .api }
490
/**
491
* Interface for filtering artifacts during resolution
492
*/
493
public interface ArtifactFilter {
494
/**
495
* Determines if an artifact should be included
496
* @param artifact artifact to test
497
* @return true if artifact should be included
498
*/
499
boolean include(Artifact artifact);
500
}
501
```
502
503
### ResolutionListener
504
505
```java { .api }
506
/**
507
* Listener interface for artifact resolution events
508
*/
509
public interface ResolutionListener {
510
/**
511
* Called when testing an artifact for inclusion
512
* @param node artifact being tested
513
*/
514
void testArtifact(DependencyNode node);
515
516
/**
517
* Called when starting resolution process
518
* @param node starting node
519
*/
520
void startProcessChildren(DependencyNode node);
521
522
/**
523
* Called when resolution process completes
524
* @param node completed node
525
*/
526
void endProcessChildren(DependencyNode node);
527
}
528
```
529
530
### TransferListener
531
532
```java { .api }
533
/**
534
* Listener interface for transfer events (from Wagon)
535
*/
536
public interface TransferListener {
537
/**
538
* Called when transfer is initiated
539
* @param transferEvent transfer event
540
*/
541
void transferInitiated(TransferEvent transferEvent);
542
543
/**
544
* Called when transfer starts
545
* @param transferEvent transfer event
546
*/
547
void transferStarted(TransferEvent transferEvent);
548
549
/**
550
* Called when transfer progresses
551
* @param transferEvent transfer event
552
*/
553
void transferProgress(TransferEvent transferEvent);
554
555
/**
556
* Called when transfer completes
557
* @param transferEvent transfer event
558
*/
559
void transferCompleted(TransferEvent transferEvent);
560
561
/**
562
* Called when transfer encounters error
563
* @param transferEvent transfer event
564
*/
565
void transferError(TransferEvent transferEvent);
566
}
567
```
568
569
## Exception Handling
570
571
### ArtifactDeploymentException
572
573
```java { .api }
574
/**
575
* Exception thrown when artifact deployment fails
576
*/
577
public class ArtifactDeploymentException extends Exception {
578
public ArtifactDeploymentException(String message);
579
public ArtifactDeploymentException(String message, Throwable cause);
580
}
581
```
582
583
### ArtifactInstallationException
584
585
```java { .api }
586
/**
587
* Exception thrown when artifact installation fails
588
*/
589
public class ArtifactInstallationException extends Exception {
590
public ArtifactInstallationException(String message);
591
public ArtifactInstallationException(String message, Throwable cause);
592
}
593
```
594
595
### ArtifactResolutionException
596
597
```java { .api }
598
/**
599
* Exception thrown when artifact resolution fails
600
*/
601
public class ArtifactResolutionException extends Exception {
602
public ArtifactResolutionException(String message);
603
public ArtifactResolutionException(String message, Throwable cause);
604
}
605
```
606
607
### ArtifactNotFoundException
608
609
```java { .api }
610
/**
611
* Exception thrown when a required artifact cannot be found
612
*/
613
public class ArtifactNotFoundException extends Exception {
614
public ArtifactNotFoundException(String message);
615
public ArtifactNotFoundException(String message, Throwable cause);
616
}
617
```
618
619
### UnknownRepositoryLayoutException
620
621
```java { .api }
622
/**
623
* Exception thrown when repository layout is not recognized
624
*/
625
public class UnknownRepositoryLayoutException extends InvalidRepositoryException {
626
/**
627
* Creates exception for unknown layout
628
* @param repositoryId repository identifier
629
* @param layoutId layout identifier that was not found
630
*/
631
public UnknownRepositoryLayoutException(String repositoryId, String layoutId);
632
633
/**
634
* Creates exception for unknown layout with cause
635
* @param repositoryId repository identifier
636
* @param layoutId layout identifier that was not found
637
* @param cause underlying cause
638
*/
639
public UnknownRepositoryLayoutException(String repositoryId, String layoutId, ComponentLookupException cause);
640
641
/**
642
* Gets the layout identifier that was not found
643
* @return layout identifier
644
*/
645
public String getLayoutId();
646
}
647
```