DEV Community

Cover image for πŸ† Default πŸ”— Maven and β˜• Java settings per project
Carlos Chacin β˜•πŸ‘½
Carlos Chacin β˜•πŸ‘½

Posted on β€’ Originally published at carloschac.in on

1

πŸ† Default πŸ”— Maven and β˜• Java settings per project

I generally use many different options on maven projects to set up things like memory lower and upper limits, fail at the end, the process in batch, use x number of threads, etc. In addition to this, sometimes I need to pass flags to the JVM like add modules, garbage collector flags, etc., and it is difficult to remember and also error-prone to have something like this:

$ JAVA_OPTS="-Xms512m -Xmx1024m -Djava.awt.headless=true" \
  mvn -B -T 4 -fae -P ci verify
Enter fullscreen mode Exit fullscreen mode

or even worst with the extended version of the flags:

$ JAVA_OPTS="-Xms512m -Xmx1024m -Djava.awt.headless=true" \
mvn --batch-mode --threads 4 -fail-at-end --activate-profiles ci verify
Enter fullscreen mode Exit fullscreen mode

Fortunately for us, since maven 3.3.1, we now can setup this per project, including the flags in these two files relatives to the project directory:

.mvn/maven.config with:

-B -T 4 -fae -P ci
Enter fullscreen mode Exit fullscreen mode

.mvn/jvm.config with:

-Xms512m -Xmx1024m -Djava.awt.headless=true
Enter fullscreen mode Exit fullscreen mode

Now, all we need to do is run the maven command, and the settings in the files will be honored:

$ mvn verify
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay