…and a bonus: one promising change not to try just yet.
Enable runtime @NotNull
checks
To enable these checks you need to tell MPS that you want your Java code compiled using the IntelliJ compiler.
- In the
project structure
settings, find or add ajava options
node. - Change the compiler to
IntelliJ
. - Define
idea_home
folder macro, set it to the MPS home (mps_home
ormps.home
variable).
The result should look like this:
This will change the generated build script to use JetBrains-specific Ant task called javac2
instead of the default
javac
task. The javac2
task wraps javac
, adding not-null checks and some (unrelated) IntelliJ IDEA GUI Designer
form functionality.
Enable copying of resources to avoid problems with images
MPS defaults to not copying resources (non-Java files) generated by a build into JAR files. This default is, in my opinion, unfortunate and should be fixed1. Until it is fixed though, enable the copying of resources manually:
- In the
project structure
settings, find or add ajava options
node. - Make sure
copy resources
is set totrue
.
Enabling copy resources
reveals resource patterns
option. Unless you have specific reasons to change it, leave it
at its default setting (<all non-java files>
).
The final result should look like this:
Move the tests build into a separate solution
The MPS build will package complete solutions into the final artifact. The build solution often needs to be packaged as well. To avoid tests leaking into the final product, it therefore makes sense to move the tests build script into a separate solution.
On the other side, two build solutions for a small project may be overkill. Packaging a build script that refers to some modules but not packaging those modules is actually harmless, in that it will not cause any errors or compilation failures (assuming that the consumer does not reference the test build script). The problem is merely too much disclosure, so decide for yourself.
BONUS: Avoiding double Java compilation… but not yet
MPS 2021.3.1 and above offer an experimental feature in the inspector of the mps
plugin:
The reason for existence of this feature is the fact that by default MPS will compile your Java code twice. Once as part
of the MPS make process trigggered by the generate
Ant task, and a second time before assembling the artifact by a
standard javac
task (or IntelliJ-specific javac2
task, if you enable the IntelliJ compiler as described above).
Enabling “single MPS Make task” will replace the generate
task with a rather similar but better named mps.make
task and disable the second compilation, slightly improving the build times. However, as of early 2023, the mps.make
task is
quite
buggy in all
currently released MPS versions. So, keep an eye on the bugs, vote for the ones important to you, and once they are
fixed, give it a try.