Skip to content

Commit 6132cc8

Browse files
gzm55slandelle
authored andcommitted
support release compiler options for javac and scalac
1 parent a33c876 commit 6132cc8

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/main/java/scala_maven/ScalaMojoSupport.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ public abstract class ScalaMojoSupport extends AbstractMojo {
9999
@Parameter(property = "addScalacArgs")
100100
private String addScalacArgs;
101101

102+
/** The -target argument for the Scala compiler. */
103+
@Parameter(property = "scala.compiler.target")
104+
protected String scalacTarget;
105+
106+
/** The -release argument for the Scala compiler, supported since scala 2.13. */
107+
@Parameter(property = "scala.compiler.release")
108+
protected String scalacRelease;
109+
110+
102111
/** override the className (FQN) of the scala tool */
103112
@Parameter(required = false, property = "maven.scala.className")
104113
protected String scalaClassName;
@@ -154,6 +163,10 @@ public abstract class ScalaMojoSupport extends AbstractMojo {
154163
@Parameter(property = "maven.compiler.target")
155164
protected String target;
156165

166+
/** The --release argument for the Java compiler (when using incremental compiler), supported since Java9. */
167+
@Parameter(property = "maven.compiler.release")
168+
protected String release;
169+
157170
/** The -encoding argument for the Java compiler. (when using incremental compiler). */
158171
@Parameter(property = "project.build.sourceEncoding", defaultValue = "UTF-8")
159172
protected String encoding;
@@ -577,6 +590,15 @@ protected List<String> getScalaOptions() throws Exception {
577590
Collections.addAll(options, StringUtils.split(addScalacArgs, "|"));
578591
}
579592
options.addAll(getCompilerPluginOptions());
593+
594+
if (scalacTarget != null && !scalacTarget.isEmpty()) {
595+
options.add("-target:" + scalacTarget);
596+
}
597+
if (scalacRelease != null && !scalacRelease.isEmpty()) {
598+
options.add("-release");
599+
options.add(scalacRelease);
600+
}
601+
580602
return options;
581603
}
582604

@@ -591,13 +613,18 @@ protected List<String> getJavacOptions() {
591613
if (javacGenerateDebugSymbols) {
592614
options.add("-g");
593615
}
594-
if (target != null && !target.isEmpty()) {
595-
options.add("-target");
596-
options.add(target);
597-
}
598-
if (source != null && !source.isEmpty()) {
599-
options.add("-source");
600-
options.add(source);
616+
if (release != null && !release.isEmpty()) {
617+
options.add("--release");
618+
options.add(release);
619+
} else {
620+
if (target != null && !target.isEmpty()) {
621+
options.add("-target");
622+
options.add(target);
623+
}
624+
if (source != null && !source.isEmpty()) {
625+
options.add("-source");
626+
options.add(source);
627+
}
601628
}
602629
if (encoding != null) {
603630
options.add("-encoding");

0 commit comments

Comments
 (0)