0
# Plugin Registry
1
2
Plugin mapping information for groupId-level metadata, enabling Maven plugin resolution by prefix and maintaining plugin directory indices.
3
4
## Capabilities
5
6
### Plugin Class
7
8
Plugin information for groupId directories, providing mappings between plugin prefixes, names, and artifactIds.
9
10
```java { .api }
11
/**
12
* Plugin mapping information for groupId directories
13
* Maps plugin prefixes to artifactIds for Maven plugin resolution
14
*/
15
public class Plugin implements Serializable, Cloneable {
16
// Constructors
17
public Plugin();
18
19
// Plugin identification
20
public String getName();
21
public void setName(String name);
22
public String getPrefix();
23
public void setPrefix(String prefix);
24
public String getArtifactId();
25
public void setArtifactId(String artifactId);
26
27
// Object operations
28
public Plugin clone();
29
}
30
```
31
32
**Usage Examples:**
33
34
```java
35
import org.apache.maven.artifact.repository.metadata.Plugin;
36
37
// Create plugin mapping for compiler plugin
38
Plugin compilerPlugin = new Plugin();
39
compilerPlugin.setName("Apache Maven Compiler Plugin");
40
compilerPlugin.setPrefix("compiler");
41
compilerPlugin.setArtifactId("maven-compiler-plugin");
42
43
// Create plugin mapping for surefire plugin
44
Plugin surefirePlugin = new Plugin();
45
surefirePlugin.setName("Maven Surefire Plugin");
46
surefirePlugin.setPrefix("surefire");
47
surefirePlugin.setArtifactId("maven-surefire-plugin");
48
49
// Plugin properties
50
System.out.println("Plugin name: " + compilerPlugin.getName());
51
System.out.println("Plugin prefix: " + compilerPlugin.getPrefix());
52
System.out.println("Plugin artifactId: " + compilerPlugin.getArtifactId());
53
```
54
55
### Plugin Management in Metadata
56
57
Plugin registration and management at the groupId level for enabling prefix-based plugin resolution.
58
59
```java { .api }
60
// Plugin management methods in Metadata class
61
public List<Plugin> getPlugins();
62
public void setPlugins(List<Plugin> plugins);
63
public void addPlugin(Plugin plugin);
64
public void removePlugin(Plugin plugin);
65
```
66
67
**Usage Examples:**
68
69
```java
70
import org.apache.maven.artifact.repository.metadata.Metadata;
71
import org.apache.maven.artifact.repository.metadata.Plugin;
72
import java.util.List;
73
74
// Create groupId-level metadata
75
Metadata groupMetadata = new Metadata();
76
groupMetadata.setGroupId("org.apache.maven.plugins");
77
78
// Add compiler plugin
79
Plugin compilerPlugin = new Plugin();
80
compilerPlugin.setName("Apache Maven Compiler Plugin");
81
compilerPlugin.setPrefix("compiler");
82
compilerPlugin.setArtifactId("maven-compiler-plugin");
83
groupMetadata.addPlugin(compilerPlugin);
84
85
// Add surefire plugin
86
Plugin surefirePlugin = new Plugin();
87
surefirePlugin.setName("Maven Surefire Plugin");
88
surefirePlugin.setPrefix("surefire");
89
surefirePlugin.setArtifactId("maven-surefire-plugin");
90
groupMetadata.addPlugin(surefirePlugin);
91
92
// Add failsafe plugin
93
Plugin failsafePlugin = new Plugin();
94
failsafePlugin.setName("Maven Failsafe Plugin");
95
failsafePlugin.setPrefix("failsafe");
96
failsafePlugin.setArtifactId("maven-failsafe-plugin");
97
groupMetadata.addPlugin(failsafePlugin);
98
99
// Access plugin list
100
List<Plugin> plugins = groupMetadata.getPlugins();
101
System.out.println("Number of plugins: " + plugins.size());
102
103
// Find plugin by prefix
104
for (Plugin plugin : plugins) {
105
if ("compiler".equals(plugin.getPrefix())) {
106
System.out.println("Found compiler plugin: " + plugin.getArtifactId());
107
break;
108
}
109
}
110
111
// Remove a plugin
112
groupMetadata.removePlugin(failsafePlugin);
113
```
114
115
### Plugin Resolution Workflow
116
117
How plugins are resolved using the registry information stored in groupId-level metadata.
118
119
**Plugin Resolution Process:**
120
121
1. **Prefix lookup**: Maven searches groupId-level metadata for plugin prefix
122
2. **ArtifactId mapping**: Maps prefix to specific artifactId
123
3. **Plugin loading**: Loads plugin using resolved groupId/artifactId combination
124
125
**Example Resolution:**
126
127
```java
128
// When user runs: mvn compiler:compile
129
// Maven resolves this to: org.apache.maven.plugins:maven-compiler-plugin
130
131
// Step 1: Look in org.apache.maven.plugins group metadata
132
Metadata groupMetadata = readGroupMetadata("org.apache.maven.plugins");
133
134
// Step 2: Find plugin with prefix "compiler"
135
Plugin resolvedPlugin = null;
136
for (Plugin plugin : groupMetadata.getPlugins()) {
137
if ("compiler".equals(plugin.getPrefix())) {
138
resolvedPlugin = plugin;
139
break;
140
}
141
}
142
143
// Step 3: Use resolved artifactId
144
if (resolvedPlugin != null) {
145
String artifactId = resolvedPlugin.getArtifactId(); // "maven-compiler-plugin"
146
// Maven can now load: org.apache.maven.plugins:maven-compiler-plugin
147
}
148
```
149
150
### Plugin Metadata Merging
151
152
Plugin merging logic during metadata consolidation from multiple sources.
153
154
**Merging Behavior:**
155
156
- **Deduplication by prefix**: Plugins with same prefix are not duplicated
157
- **No overwrites**: Existing plugins are preserved during merge operations
158
- **Additive merging**: New plugins from source metadata are added to target
159
160
**Usage Examples:**
161
162
```java
163
// Local metadata with some plugins
164
Metadata localMetadata = new Metadata();
165
localMetadata.setGroupId("org.apache.maven.plugins");
166
167
Plugin compilerPlugin = new Plugin();
168
compilerPlugin.setPrefix("compiler");
169
compilerPlugin.setArtifactId("maven-compiler-plugin");
170
localMetadata.addPlugin(compilerPlugin);
171
172
// Remote metadata with additional plugins
173
Metadata remoteMetadata = new Metadata();
174
remoteMetadata.setGroupId("org.apache.maven.plugins");
175
176
Plugin surefirePlugin = new Plugin();
177
surefirePlugin.setPrefix("surefire");
178
surefirePlugin.setArtifactId("maven-surefire-plugin");
179
remoteMetadata.addPlugin(surefirePlugin);
180
181
// Merge remote plugins into local metadata
182
boolean changed = localMetadata.merge(remoteMetadata);
183
if (changed) {
184
// Local metadata now contains both compiler and surefire plugins
185
System.out.println("Plugins merged successfully");
186
System.out.println("Total plugins: " + localMetadata.getPlugins().size());
187
}
188
```
189
190
## Common Plugin Prefixes
191
192
Standard Maven plugin prefixes commonly found in repositories:
193
194
| Prefix | ArtifactId | Purpose |
195
|--------|------------|---------|
196
| compiler | maven-compiler-plugin | Java compilation |
197
| surefire | maven-surefire-plugin | Unit test execution |
198
| failsafe | maven-failsafe-plugin | Integration test execution |
199
| jar | maven-jar-plugin | JAR file creation |
200
| war | maven-war-plugin | WAR file creation |
201
| clean | maven-clean-plugin | Clean lifecycle |
202
| install | maven-install-plugin | Install to local repository |
203
| deploy | maven-deploy-plugin | Deploy to remote repository |
204
| site | maven-site-plugin | Site generation |
205
| assembly | maven-assembly-plugin | Assembly creation |
206
207
## Error Handling
208
209
Plugin registry includes robust error handling:
210
211
- **Null safety**: Empty plugin lists instead of null collections
212
- **Clone support**: Deep cloning preserves all plugin data
213
- **Serialization**: Full serialization support for persistence
214
- **Duplicate prevention**: Merge operations prevent duplicate prefixes