How to get target name in maven2 Mojo at runtime

For Maven2, how can I get the name of the target currently executing in a Mojo runtime? Exactly I need the value of the @goal attribute inside the Mojo execute method.

0


source to share


1 answer


public static String getGoalName(PluginDescriptor pluginDescriptor, String mojoClassName) {
        String goalName=null;
        List<MojoDescriptor> mojoDescriptorList = pluginDescriptor.getMojos();
        for (MojoDescriptor mojoDescriptor : mojoDescriptorList) {
            if (mojoDescriptor.getImplementation().equals(mojoClassName)) {
                goalName=mojoDescriptor.getGoal();
                break;
            }
        }
        return goalName;
    }

      



Here, PluginDescriptor can be retrieved from pluginManager.getPluginDescriptorForPrefix ("prefix-for-your-plugin"). PluginManager is available as @component role = "org.apache.maven.plugin.PluginManager"

+1


source







All Articles