35
35
import org .apache .maven .model .Build ;
36
36
import org .apache .maven .model .Plugin ;
37
37
import org .apache .maven .plugin .MavenPluginManager ;
38
+ import org .apache .maven .plugin .PluginIncompatibleException ;
38
39
import org .apache .maven .plugin .PluginResolutionException ;
39
40
import org .apache .maven .plugin .descriptor .PluginDescriptor ;
40
41
import org .apache .maven .plugin .version .PluginVersionRequest ;
@@ -158,6 +159,8 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
158
159
throws PluginVersionResolutionException {
159
160
String version = null ;
160
161
ArtifactRepository repo = null ;
162
+ boolean resolvedPluginVersions = !versions .versions .isEmpty ();
163
+ boolean searchPerformed = false ;
161
164
162
165
if (StringUtils .isNotEmpty (versions .releaseVersion )) {
163
166
version = versions .releaseVersion ;
@@ -167,8 +170,11 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
167
170
repo = versions .latestRepository ;
168
171
}
169
172
if (version != null && !isCompatible (request , version )) {
173
+ logger .info ("Latest version of plugin " + request .getGroupId () + ":" + request .getArtifactId ()
174
+ + " failed compatibility check" );
170
175
versions .versions .remove (version );
171
176
version = null ;
177
+ searchPerformed = true ;
172
178
}
173
179
174
180
if (version == null ) {
@@ -191,16 +197,26 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
191
197
}
192
198
}
193
199
194
- for (Version v : releases ) {
195
- String ver = v .toString ();
196
- if (isCompatible (request , ver )) {
197
- version = ver ;
198
- repo = versions .versions .get (version );
199
- break ;
200
+ if (!releases .isEmpty ()) {
201
+ logger .info ("Looking for compatible RELEASE version of plugin "
202
+ + request .getGroupId ()
203
+ + ":"
204
+ + request .getArtifactId ());
205
+ for (Version v : releases ) {
206
+ String ver = v .toString ();
207
+ if (isCompatible (request , ver )) {
208
+ version = ver ;
209
+ repo = versions .versions .get (version );
210
+ break ;
211
+ }
200
212
}
201
213
}
202
214
203
- if (version == null ) {
215
+ if (version == null && !snapshots .isEmpty ()) {
216
+ logger .info ("Looking for compatible SNAPSHOT version of plugin "
217
+ + request .getGroupId ()
218
+ + ":"
219
+ + request .getArtifactId ());
204
220
for (Version v : snapshots ) {
205
221
String ver = v .toString ();
206
222
if (isCompatible (request , ver )) {
@@ -213,15 +229,27 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
213
229
}
214
230
215
231
if (version != null ) {
232
+ // if LATEST worked out of the box, remain silent as today, otherwise inform user about search result
233
+ if (searchPerformed ) {
234
+ logger .info ("Selected plugin " + request .getGroupId () + ":" + request .getArtifactId () + ":" + version );
235
+ }
216
236
result .setVersion (version );
217
237
result .setRepository (repo );
218
238
} else {
239
+ logger .warn ((resolvedPluginVersions
240
+ ? "Could not find compatible version of plugin in any plugin repository: "
241
+ : "Plugin not found in any plugin repository: " )
242
+ + request .getGroupId ()
243
+ + ":"
244
+ + request .getArtifactId ());
219
245
throw new PluginVersionResolutionException (
220
246
request .getGroupId (),
221
247
request .getArtifactId (),
222
248
request .getRepositorySession ().getLocalRepository (),
223
249
request .getRepositories (),
224
- "Plugin not found in any plugin repository" );
250
+ resolvedPluginVersions
251
+ ? "Could not find compatible plugin version in any plugin repository"
252
+ : "Plugin not found in any plugin repository" );
225
253
}
226
254
}
227
255
@@ -246,8 +274,12 @@ private boolean isCompatible(PluginVersionRequest request, String version) {
246
274
247
275
try {
248
276
pluginManager .checkRequiredMavenVersion (pluginDescriptor );
249
- } catch (Exception e ) {
250
- logger .debug ("Ignoring incompatible plugin version " + version + ": " + e .getMessage ());
277
+ } catch (PluginIncompatibleException e ) {
278
+ if (logger .isDebugEnabled ()) {
279
+ logger .warn ("Ignoring incompatible plugin version " + version , e );
280
+ } else {
281
+ logger .warn ("Ignoring incompatible plugin version " + version + ": " + e .getMessage ());
282
+ }
251
283
return false ;
252
284
}
253
285
0 commit comments