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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️