The scala-maven-plugin allows for two ways to run code with a Maven goal. Both way require a different approach to specifying JVM arguments, for example to set the SLF4j log level via org.slf4j.simpleLogger.defaultLogLevel.

Running a main method

The first method is to run a main method in some object with mvn scala:run. To do so, you have to configure a launcher in the pom-xml:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>scala-maven-plugin</artifactId>
  <version>3.4.4</version>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <launchers>
      <launcher>
        <mainClass>org.package.objectWithMain</mainClass>
        <jvmArgs>
          <!-- Set the log level to one of the following values:
            debug (most verbose)
            info
            warn
            error (least verbose)
            -->
          <jvmArg>-Dorg.slf4j.simpleLogger.defaultLogLevel=info</jvmArg>
        </jvmArgs>
      </launcher>
    </launchers>
  </configuration>
</plugin>

As you can see, it is possible to configure JVM arguments for the launcher right in the pom.xml. When executing the launcher, the scala-maven-plugin runs the main method in a forked JVM, which is started with the arguments in the jvmArgs tag.

Running a script

Alternatively, you can run arbitrary Scala code with mvn scala:script. This requires a similar, but shorter entry int the pom.xml:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>scala-maven-plugin</artifactId>
  <version>3.4.4</version>
  <configuration>
    <scriptFile>ScriptFile.scala</scriptFile>
  </configuration>
</plugin>

The jvmArgs can not be configured here. When executing a script, the scala-maven-plugin runs it in the same JVM in which Maven is running. Consequently, you already have to set JVM arguments when starting Maven. An easy way to do so was introduced in Maven 3.3.1: You can just create the file .mvn/jvm.config in your Maven project’s root directory and put the JVM arguments in there:

-Dorg.slf4j.simpleLogger.defaultLogLevel=error

However, this seems to mess with Maven’s own logging, so it might be a good idea to not use the script goal if you want a robust way to set JVM arguments for your application.