Skip to content

Instantly share code, notes, and snippets.

@gturi
Last active March 27, 2024 14:38
Show Gist options
  • Save gturi/d7b3a0d4154af97707cbff8b3a514f4e to your computer and use it in GitHub Desktop.
Save gturi/d7b3a0d4154af97707cbff8b3a514f4e to your computer and use it in GitHub Desktop.

Useful maven commands

Specify jdk to use for running maven command

function mvn() {
   MVN_HOME=/home/gventurini/Programs/apache-maven-3.6.3/bin/mvn
   JAVA_HOME=/home/gventurini/.jdks/corretto-1.8.0_342 "$MVN_HOME" "$1"
}

Overrried java property

spring-boot:run -Dspring.profiles.active=debug -Denvironment.endpoint=https://my.company.dev.endpoint.com

Test utilities

# -DforkCount=0 allows to attach debugger in intellij
# -Dsurefire.useFile=false
# -DtrimStackTrace=false this avoids stacktrace trimming

# run every test
test -DforkCount=0 -Dsurefire.useFile=false -DtrimStackTrace=false
# run test in a class
test -Dtest=ClassToTest -DforkCount=0 -Dsurefire.useFile=false -DtrimStackTrace=false
# run specific test in a class
test -Dtest=ClassToTest#methodToTest -DforkCount=0 -Dsurefire.useFile=false -DtrimStackTrace=false

See what the final pom will be when inheriting from parent

mvn help:effective-pom

Show dependency tree

# useful to discover possible classpath clash errors
mvn dependency:tree -Dverbose

Upgrade maven wrapper

mvn wrapper:wrapper -Dmaven=3.9.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment