DEV Community

Cover image for 🏆 Default 🔗 Maven and ☕ Java settings per project
Carlos Chacin ☕👽
Carlos Chacin ☕👽

Posted on • Originally published at carloschac.in on

🏆 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

Top comments (0)