Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created June 26, 2014 15:56
Show Gist options
  • Select an option

  • Save Riduidel/2df79e859bfbf83c0e5c to your computer and use it in GitHub Desktop.

Select an option

Save Riduidel/2df79e859bfbf83c0e5c to your computer and use it in GitHub Desktop.
Get version of an unversionned plugin to use with Mojo Executor
/**
* Creates a plugin from source one with version set according to project dependency management and other rules ..
* @param environment
* @param plugin
* @return
*/
private static Plugin findVersionOf(MavenEnvironment environment, final Plugin plugin) {
SortedSet<Plugin> candidates = new TreeSet<Plugin>();
if(plugin.getVersion()!=null)
return plugin;
Iterable<Plugin> plugins = Iterables.concat(environment.project.getPluginManagement().getPlugins(), environment.project.getBuildPlugins());
Iterable<Plugin> matching = Iterables.filter(plugins, new Predicate<Plugin>() {
@Override
public boolean apply(Plugin input) {
return input.getArtifactId().equals(plugin.getArtifactId()) && input.getGroupId().equals(plugin.getGroupId());
}});
Plugin found = Iterables.getFirst(matching, null);
if(found==null)
throw new UnsupportedMavenPluginException("plugin "+plugin+" isn't declared in this project. You should set its version by hand !");
return found;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment