typelevel / sbt-tpolecat

scalac options for the enlightened

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Also set `javacOption`

armanbilge opened this issue · comments

sbt-typelevel-settings currently sets:

javacOptions ++= Seq(
  "-encoding",
  "utf8",
  "-Xlint:all"
),

and

javacOptions ++= {
  if (tlFatalWarnings.value)
    Seq("-Werror")
  else
    Seq.empty
},

I started a PR to add these to sbt-tpolecat. Would the idea be to go all-out and add class JavacOption and stuff?

If Someone™️ wants to do the work to add a JavacOptions DSL I don't have any objection in principle, but since I rarely use mixed projects personally I wasn't planning to do it myself. 😛
We'd need to bear in mind that javac options have evolved over time in much the same way as Scala compiler options, although generally with much greater attention to deprecating old options before removal.
I don't have any objection to setting javacOptions directly either.
Both are definitely a breaking change for users that currently set their own javacOptions.

BTW, how do you think that tlFatalWarnings and tpolecatOptionsMode should be unified?

Yeah, it's somewhat a question of philosophy. If The sbt-tpolecat Way is to individually add lints instead of doing the lazy -Xlint:all, then probably this doesn't make sense and it can just be an sbt-typelevel-settings thing.

BTW, how do you think that tlFatalWarnings and tpolecatOptionsMode should be unified?

That's a good question. I'm a little confused I guess. If you want to disable fatal warnings for part of your build for whatever reason, how would you do that with sbt-tpolecat?

At the moment there are different modes for the plugin, and default "option sets" for each mode. For the "development" mode we have:

tpolecatDevModeOptions := ScalacOptions.default

for "CI" mode we have:

tpolecatCiModeOptions := tpolecatDevModeOptions.value + ScalacOptions.fatalWarnings

for "release" mode we have:

tpolecatReleaseModeOptions := tpolecatCiModeOptions.value + ScalacOptions.optimizerMethodLocal

If you want to enable a certain mode you can either use a command:

> tpolecatDevMode

or set an environment variable:

SBT_TPOLECAT_DEV=true sbt prePR

If no environment variable is set then you get the default mode (CI mode).

So at the moment, if you want to disable fatal warnings, you can either fiddle with the option sets to set them how you like in each mode, or set SBT_TPOLECAT_DEV to any value in your CI build, or run the tpolecatDevMode command as the first part of a command chain.

The reason that the default mode is the CI mode is that existing users didn't want the behaviour to change (i.e. fatal warnings should be enabled in the default configuration for this plugin).

If you want to disable fatal warnings for part of your build for whatever reason, how would you do that with sbt-tpolecat?

To answer this specific question, you could do something like:

lazy val foo = project.in(file("foo"))
  .settings(
    tpolecatScalacOptions ~= { _.filterNot(Set(ScalacOptions.fatalWarnings)) }
  )

Or you could set the more specific option key just for the default mode tpolecatCiModeOptions if you wanted to be extremely specific.

Ok, thanks, that's helpful. So tlFatalWarnings might live on as a one liner to do that ☝️

I have a PR open with sbt to make removing options nicer (sbt/sbt#6856) but unfortunately it's stuck on a legal review of the CLA at the moment 😢

Good places to look to understand what we need to configure here:

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
https://docs.oracle.com/en/java/javase/11/tools/javac.html
https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html

Annoyingly the page for the javac command keeps moving in each JDK release 😆