0
# Maven Compat
1
2
Maven Compat is a Java library that provides backward compatibility for Maven2 APIs within the Apache Maven ecosystem. This compatibility layer preserves legacy Maven2 APIs and functionality that may still be needed by plugins or tools built for earlier versions of Maven, enabling smooth transitions and continued operation of older Maven-based tools and plugins.
3
4
## Package Information
5
6
- **Package Name**: org.apache.maven:maven-compat
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add dependency to your Maven `pom.xml`:
10
11
```xml
12
<dependency>
13
<groupId>org.apache.maven</groupId>
14
<artifactId>maven-compat</artifactId>
15
<version>3.9.11</version>
16
</dependency>
17
```
18
19
## Core Imports
20
21
```java
22
// Runtime information
23
import org.apache.maven.execution.RuntimeInformation;
24
import org.apache.maven.execution.DefaultRuntimeInformation;
25
26
// Artifact management
27
import org.apache.maven.artifact.ArtifactScopeEnum;
28
import org.apache.maven.artifact.ArtifactStatus;
29
30
// Artifact operations
31
import org.apache.maven.artifact.deployer.ArtifactDeployer;
32
import org.apache.maven.artifact.installer.ArtifactInstaller;
33
import org.apache.maven.artifact.resolver.ArtifactResolver;
34
35
// Repository operations
36
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
37
38
// Profile management
39
import org.apache.maven.profiles.ProfileManager;
40
import org.apache.maven.profiles.DefaultProfileManager;
41
42
// Project building
43
import org.apache.maven.project.MavenProjectBuilder;
44
import org.apache.maven.project.ProjectBuilderConfiguration;
45
46
// Legacy repository system
47
import org.apache.maven.repository.legacy.LegacyRepositorySystem;
48
```
49
50
## Basic Usage
51
52
```java
53
// Create a runtime information instance
54
RuntimeInformation runtimeInfo = new DefaultRuntimeInformation();
55
ArtifactVersion version = runtimeInfo.getApplicationVersion();
56
57
// Work with artifact scopes
58
ArtifactScopeEnum scope = ArtifactScopeEnum.compile;
59
boolean includesTest = scope.encloses(ArtifactScopeEnum.test);
60
61
// Create artifact status
62
ArtifactStatus status = ArtifactStatus.valueOf("DEPLOYED");
63
64
// Use profile manager for profile activation
65
ProfileManager profileManager = new DefaultProfileManager();
66
profileManager.explicitlyActivate("production");
67
List activeProfiles = profileManager.getActiveProfiles();
68
69
// Repository operations through legacy system
70
LegacyRepositorySystem repoSystem = new LegacyRepositorySystem();
71
ArtifactRepository localRepo = repoSystem.createDefaultLocalRepository();
72
```
73
74
## Architecture
75
76
Maven Compat is organized into several key functional areas:
77
78
- **Runtime System**: Version information and execution context compatibility
79
- **Artifact Management**: Core artifact handling, scoping, and status tracking
80
- **Repository Operations**: Legacy repository system with artifact deployment, installation, and resolution
81
- **Profile Management**: Maven profile activation and configuration
82
- **Project Building**: Legacy project model building and validation
83
- **Metadata Processing**: Dependency graph management and classpath transformation
84
- **Transport Layer**: Wagon-based transport protocol management (deprecated)
85
86
**Important Note**: Most APIs in this library are marked as `@Deprecated` and are maintained solely for backward compatibility. New development should use the corresponding Maven 3.x APIs where available.
87
88
## Capabilities
89
90
### Runtime Information
91
92
Provides Maven runtime version information and execution context for compatibility with Maven2 patterns.
93
94
```java { .api }
95
public interface RuntimeInformation {
96
ArtifactVersion getApplicationVersion();
97
}
98
99
public class DefaultRuntimeInformation implements RuntimeInformation {
100
public ArtifactVersion getApplicationVersion();
101
}
102
```
103
104
[Runtime Information](./runtime-information.md)
105
106
### Artifact Management
107
108
Core artifact management functionality including scoping, status tracking, and repository layout support.
109
110
```java { .api }
111
public enum ArtifactScopeEnum {
112
compile(1), test(2), runtime(3), provided(4), system(5), runtime_plus_system(6);
113
114
String getScope();
115
boolean encloses(ArtifactScopeEnum scope);
116
static ArtifactScopeEnum checkScope(ArtifactScopeEnum scope);
117
}
118
119
public class ArtifactStatus implements Comparable<ArtifactStatus> {
120
public static final ArtifactStatus NONE, GENERATED, CONVERTED, PARTNER, DEPLOYED, VERIFIED;
121
122
static ArtifactStatus valueOf(String status);
123
int compareTo(ArtifactStatus s);
124
}
125
```
126
127
[Artifact Management](./artifact-management.md)
128
129
### Repository Operations
130
131
Legacy repository system providing artifact deployment, installation, resolution, and repository management.
132
133
```java { .api }
134
public interface ArtifactDeployer {
135
String ROLE = ArtifactDeployer.class.getName();
136
137
void deploy(File source, Artifact artifact, ArtifactRepository deploymentRepository,
138
ArtifactRepository localRepository) throws ArtifactDeploymentException;
139
}
140
141
public interface ArtifactInstaller {
142
String ROLE = ArtifactInstaller.class.getName();
143
144
void install(File source, Artifact artifact, ArtifactRepository localRepository)
145
throws ArtifactInstallationException;
146
}
147
148
public interface ArtifactResolver {
149
ArtifactResolutionResult resolve(ArtifactResolutionRequest request);
150
151
// Many deprecated methods also available - see sub-doc for complete API
152
}
153
```
154
155
[Repository Operations](./repository-operations.md)
156
157
### Profile Management
158
159
Maven profile activation and management system for backward compatibility with Maven2 profile handling.
160
161
```java { .api }
162
public interface ProfileManager {
163
void addProfile(Profile profile);
164
void explicitlyActivate(String profileId);
165
void explicitlyDeactivate(String profileId);
166
List getActiveProfiles() throws ProfileActivationException;
167
Properties getRequestProperties();
168
}
169
170
public interface MavenProfilesBuilder {
171
String ROLE = MavenProfilesBuilder.class.getName();
172
173
ProfilesRoot buildProfiles(File basedir) throws ProfilesBuilderException;
174
}
175
```
176
177
[Profile Management](./profile-management.md)
178
179
### Project Building
180
181
Legacy project building system for constructing Maven projects from POM files with Maven2 compatibility.
182
183
```java { .api }
184
public interface MavenProjectBuilder {
185
MavenProject build(File pom, ProjectBuilderConfiguration configuration)
186
throws ProjectBuildingException;
187
MavenProject buildFromRepository(Artifact artifact, List<ArtifactRepository> remoteRepositories,
188
ArtifactRepository localRepository) throws ProjectBuildingException;
189
MavenProject buildStandaloneSuperProject(ProjectBuilderConfiguration configuration)
190
throws ProjectBuildingException;
191
}
192
193
public interface ProjectBuilderConfiguration {
194
// Configuration methods for project building
195
}
196
```
197
198
[Project Building](./project-building.md)
199
200
### Metadata Processing
201
202
Dependency metadata processing, graph management, and classpath transformation for legacy compatibility.
203
204
```java { .api }
205
public interface MetadataSource {
206
String ROLE = MetadataSource.class.getName();
207
208
MetadataResolution retrieve(ArtifactMetadata artifact, ArtifactRepository localRepository,
209
List<ArtifactRepository> remoteRepositories) throws MetadataRetrievalException;
210
}
211
212
public interface ClasspathTransformation {
213
String ROLE = ClasspathTransformation.class.getName();
214
215
ClasspathContainer transform(MetadataGraph dirtyGraph, ArtifactScopeEnum scope, boolean resolve)
216
throws ClasspathTransformationException;
217
}
218
```
219
220
[Metadata Processing](./metadata-processing.md)
221
222
### Legacy Repository System
223
224
Main legacy repository system implementation providing comprehensive backward compatibility.
225
226
```java { .api }
227
public class LegacyRepositorySystem implements RepositorySystem {
228
Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type);
229
ArtifactRepository createDefaultLocalRepository() throws InvalidRepositoryException;
230
ArtifactResolutionResult resolve(ArtifactResolutionRequest request) throws ArtifactResolutionException;
231
void injectMirror(List<ArtifactRepository> repositories, List<Mirror> mirrors);
232
void injectAuthentication(List<ArtifactRepository> repositories, List<Server> servers);
233
}
234
```
235
236
[Legacy Repository System](./legacy-repository-system.md)