Skip to content

Instantly share code, notes, and snippets.

@manfredk
Last active September 13, 2024 07:42
Show Gist options
  • Save manfredk/a791109a02cc68155f042a146ffcd711 to your computer and use it in GitHub Desktop.
Save manfredk/a791109a02cc68155f042a146ffcd711 to your computer and use it in GitHub Desktop.
List all available maven goals in project
#! /bin/sh
mvn help:effective-pom 2>/dev/null | \
grep -i -E '^ *<' | \
sed -e 's/ xmlns.*=".*"//g' | \
xmlstarlet sel -t -n -o "Plugin[:phase:goal]" -n \
-o "---------------------------------------------------" -n \
-m "/project/build/plugins/plugin" -v "artifactId" -n \
-m "executions/execution" -v "../../artifactId" -o ":" -v "phase" -o ":" -m "goals" -v "goal" -n
@manfredk
Copy link
Author

manfredk commented Aug 24, 2020

mvn_list_goals.sh

This command is to be executed in a maven project folder, where the project pom resides.

  • mvn help:effective-pom
    List the effective pom (including all inherited entries)
  • 2>/dev/null
    supress stderr output
  • grep -i -E '^ *<'
    keep only lines which contain a match for the extended regex given, having zero or more blanks and a lower-than sign at the beginning
  • sed --expression 's/ xmlns.="."//g'
    stream edit the output of grep, adding the commands in the sed-script to the edit expressions used when processing the input stream. The script is a substitute following the syntax s/regex/replacement/flags and effectively deletes all (flag /g) found xml namespace attributes as matched by the regex / xmlns.*=".*"/, because replacement is empty (//). Eliminating the namespace from the xml is important for the subsequent xml-processing, since xmlstarlet is picky about proper namespacing of xml tags.
  • xmlstarlet sel -t
    process the output of sed, which is clean xml and xslt - transform it into a list of maven-plugins, phases and goals available in the current project.

example output:


Plugin[:phase:goal]
---------------------------------------------------
versions-maven-plugin
maven-compiler-plugin
maven-compiler-plugin:compile:compile
maven-compiler-plugin:test-compile:testCompile
kotlin-maven-plugin
kotlin-maven-plugin:compile:compile
kotlin-maven-plugin:test:test-compile
kotlin-maven-plugin:test-compile:test-compile
javafx-maven-plugin
maven-surefire-plugin
maven-surefire-plugin:test:test
maven-clean-plugin
maven-clean-plugin:clean:clean
maven-resources-plugin
maven-resources-plugin:process-test-resources:testResources
maven-resources-plugin:process-resources:resources
maven-jar-plugin
maven-jar-plugin:package:jar
maven-install-plugin
maven-install-plugin:install:install
maven-deploy-plugin
maven-deploy-plugin:deploy:deploy
maven-site-plugin
maven-site-plugin:site:site
maven-site-plugin:site-deploy:deploy
  • save script file as /usr/local/bin/mvn_list_goals
  • sudo chmod 777 /usr/local/bin/mvn_list_goals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment