diff --git a/modules/build/src/main/scala/scala/build/Build.scala b/modules/build/src/main/scala/scala/build/Build.scala index e5b317590e..2cbc832e33 100644 --- a/modules/build/src/main/scala/scala/build/Build.scala +++ b/modules/build/src/main/scala/scala/build/Build.scala @@ -766,8 +766,9 @@ object Build { else if (compilerJvmVersionOpt.exists(_.value == 8)) None else if ( - options.scalaOptions.scalacOptions.values.exists( - _.headOption.exists(_.value.value == "-release") + options.scalaOptions.scalacOptions.values.exists(opt => + opt.headOption.exists(_.value.value.startsWith("-release")) || + opt.headOption.exists(_.value.value.startsWith("-java-output-version")) ) ) None diff --git a/modules/build/src/test/scala/scala/build/tests/BuildOptionsTests.scala b/modules/build/src/test/scala/scala/build/tests/BuildOptionsTests.scala index 84e283042b..8801412541 100644 --- a/modules/build/src/test/scala/scala/build/tests/BuildOptionsTests.scala +++ b/modules/build/src/test/scala/scala/build/tests/BuildOptionsTests.scala @@ -368,4 +368,27 @@ class BuildOptionsTests extends munit.FunSuite { expect(semanticDbVersion == "4.8.4") } + test("skip setting release option when -release or -java-output-version is set by user") { + val javaOutputVersionOpt = "-java-output-version:16" + val inputs = TestInputs( + os.rel / "Hello.scala" -> + s"""//> using option $javaOutputVersionOpt + |""".stripMargin + ) + + inputs.withBuild(BuildOptions(), buildThreads, bloopConfigOpt, buildTests = false) { + (_, _, maybeBuild) => + expect(maybeBuild.exists(_.success)) + val build = maybeBuild + .toOption + .flatMap(_.successfulOpt) + .getOrElse(sys.error("cannot happen")) + + val scalacOpts = build.project.scalaCompiler.toSeq.flatMap(_.scalacOptions) + + expect(scalacOpts.contains(javaOutputVersionOpt)) + expect(!scalacOpts.exists(_.startsWith("-release"))) + } + } + }