7 Maven One-Liners Every Developer Should Know
![]() |
A futuristic developer workspace showcasing powerful Maven commands in a high-tech cyberpunk environment. |
Maven is an essential tool for Java developers, but many don’t realize its true power beyond just mvn clean install
. Here are seven incredibly useful one-liners that can make your development workflow smoother and more efficient.
1. Check and Update Dependency & Plugin Versions
Keeping dependencies up to date is crucial for security and stability. Use the Versions plugin to check for updates:
mvn versions:display-dependency-updates
To update them automatically:
mvn versions:use-latest-releases
Similarly, update Maven plugins:
mvn versions:display-plugin-updates
This ensures your project is always running the latest stable dependencies and plugins.
2. Run Unit Tests Without Building the Entire Project
Instead of running a full build, use this to execute only the unit tests:
mvn test
For a specific test class:
mvn -Dtest=MyTestClass test
This is a great way to speed up testing without unnecessary compilation.
3. Skip Tests for Faster Builds
Sometimes, you want a quick build without running tests:
mvn install -DskipTests
Or to completely disable tests:
mvn install -Dmaven.test.skip=true
Use with caution, as skipping tests can lead to undetected bugs.
4. Analyze Dependency Tree
To resolve dependency conflicts or check why a certain library is included:
mvn dependency:tree
For a more detailed view, including omitted dependencies:
mvn dependency:tree -Dverbose
This is invaluable when debugging classpath issues.
5. Run a Web Application Without Deployment
If you're using a web framework like Spring Boot, you can start the application without deploying it manually:
mvn spring-boot:run
For a non-Spring project with a Jetty plugin:
mvn jetty:run
This saves time during development.
6. Format Code Automatically
If your project uses the Spotless plugin:
mvn spotless:apply
This helps maintain clean and readable code.
7. Generate a Minimal, Working Maven Project
Need to start a new Maven project quickly? Use the archetype plugin:
mvn archetype:generate -DgroupId=com.example -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This creates a simple project structure with a pom.xml
and basic files ready to go.
Conclusion
These Maven one-liners can significantly improve your efficiency when working with Java projects. Whether it’s keeping dependencies up to date, skipping unnecessary steps, or debugging dependency issues, mastering these commands will make you a more effective developer.
Have a favorite Maven trick? Share it in the comments!
1 comment:
Spotless is a great choice over Checkstyle when you want automatic code formatting instead of just linting. While Checkstyle enforces coding standards and highlights violations, Spotless actually reformats your code, ensuring consistency without manual fixes. This saves time and integrates seamlessly into CI/CD pipelines.
Post a Comment