Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also set javacOption #72

Open
armanbilge opened this issue Apr 26, 2022 · 7 comments
Open

Also set javacOption #72

armanbilge opened this issue Apr 26, 2022 · 7 comments

Comments

@armanbilge
Copy link
Member

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?

@DavidGregory084
Copy link
Member

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?

@armanbilge
Copy link
Member Author

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?

@DavidGregory084
Copy link
Member

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).

@DavidGregory084
Copy link
Member

DavidGregory084 commented Apr 26, 2022

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.

@armanbilge
Copy link
Member Author

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

@DavidGregory084
Copy link
Member

DavidGregory084 commented Apr 26, 2022

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 😢

@DavidGregory084
Copy link
Member

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 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants