I'm looking for an unobtrusive way to make mvn
aware of additional flags I'd like to pass to the scalac
compiler via the command-line or environment variables only.
I'm currently using the scala-maven-plugin with a command such as:
mvn --show-version --batch-mode --errors compile
In this case I want mvn
to treat the compile stage as if it had been passed flags such as:
scalac -encoding utf8 -deprecation -unchecked -Xlint:_ -Werror -Wdead-code -Wunused:_
I do not want to touch the project's pom.xml
. The reason for that in this case is that this is a step in an upstream CI/CD templates repository, so I don't have permission to mess with the Maven configuration of the downstream projects.
It does not appear that this is what MAVEN_OPTS
is made for, so I'm wondering if there is some alternative to talk to scalac
.
Using scala:compile
with -DaddScalacArgs
allows you to pass additional flags to scalac
:
Example:
mvn \
--show-version \
--batch-mode \
--errors \
scala:compile \
-DaddScalacArgs='-unchecked|-deprecation|-explaintypes|-Xfatal-warnings|-Xlint:_'
Documentation:
Note that the available options to scalac
have changed with Scala versions.
You can use:
mvn scala:help
scalac -X
scalac -Xlint:help
To see the underlying version and the available -X
options.