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

Add JavaModule.mandatoryJavacOptions #3503

Merged
merged 11 commits into from
Sep 10, 2024
4 changes: 3 additions & 1 deletion bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ private trait MillJavaBuildServer extends JavaBuildServer { this: MillBuildServe
sem.bspCompiledClassesAndSemanticDbFiles
case _ => m.bspCompileClassesPath
}
T.task { (classesPathTask(), m.javacOptions(), m.bspCompileClasspath()) }
T.task {
(classesPathTask(), m.javacOptions() ++ m.managedJavacOptions(), m.bspCompileClasspath())
}
}
) {
// We ignore all non-JavaModule
Expand Down
6 changes: 4 additions & 2 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
def out(m: JavaModule) = bloopDir / "out" / name(m)
def classes(m: JavaModule) = out(m) / "classes"

val javaConfig =
module.javacOptions.map(opts => Some(Config.Java(options = opts.toList)))
val javaConfig = T.task {
val opts = module.javacOptions() ++ module.managedJavacOptions()
Some(Config.Java(options = opts.toList))
}

// //////////////////////////////////////////////////////////////////////////
// Scalac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ErrorProneModule extends JavaModule {
* The classpath of the `error-prone` compiler plugin.
*/
def errorProneClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task { errorProneDeps().map(bindDependency()) })()
defaultResolver().resolveDeps(errorProneDeps())
}

/**
Expand Down Expand Up @@ -70,12 +70,7 @@ trait ErrorProneModule extends JavaModule {
/**
* Appends the [[errorProneJavacEnableOptions]] to the Java compiler options.
*/
override def javacOptions: T[Seq[String]] = T {
val supOpts = super.javacOptions()
val enableOpts = Option
.when(!supOpts.exists(o => o.startsWith("-Xplugin:ErrorProne")))(
errorProneJavacEnableOptions()
)
supOpts ++ enableOpts.toSeq.flatten
override def managedJavacOptions: T[Seq[String]] = T {
super.managedJavacOptions() ++ errorProneJavacEnableOptions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ErrorProneTests extends TestSuite {
}
test("compileWarn") {
val eval = UnitTester(errorProneCustom, testModuleSourcesPath, debugEnabled = true)
val Right(opts) = eval(errorProneCustom.javacOptions)
val Right(opts) = eval(errorProneCustom.managedJavacOptions)
assert(opts.value.exists(_.contains("-XepAllErrorsAsWarnings")))
val res = eval(errorProneCustom.compile)
assert(res.isRight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait HelloWorldTests extends utest.TestSuite {
def scalaVersion = testScalaVersion
def scoverageVersion = testScoverageVersion

object test extends SbtModuleTests with ScoverageTests with TestModule.ScalaTest {
object test extends SbtTests with ScoverageTests with TestModule.ScalaTest {
override def ivyDeps = Agg(ivy"org.scalatest::scalatest:${testScalatestVersion}")
}
}
Expand Down
3 changes: 1 addition & 2 deletions contrib/testng/test/src/mill/testng/TestNGTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import mill.util.Util.millProjectModule
import mill.scalalib._
import mill.testkit.UnitTester
import mill.testkit.TestBaseModule
import utest.framework.TestPath
import utest.{TestSuite, Tests, assert, _}

object TestNGTests extends TestSuite {

object demo extends TestBaseModule with JavaModule {

object test extends JavaModuleTests {
object test extends JavaTests {
def testngClasspath = T {
millProjectModule(
"mill-contrib-testng",
Expand Down
6 changes: 5 additions & 1 deletion scalalib/src/mill/scalalib/CrossSbtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import mill.api.PathRef
import mill.T
import mill.scalalib.{CrossModuleBase, SbtModule}

import scala.annotation.nowarn

trait CrossSbtModule extends SbtModule with CrossModuleBase { outer =>

override def sources: T[Seq[PathRef]] = T.sources {
Expand All @@ -12,15 +14,17 @@ trait CrossSbtModule extends SbtModule with CrossModuleBase { outer =>
)
}

@nowarn
type CrossSbtTests = CrossSbtModuleTests
@deprecated("Use CrossSbtTests instead", since = "Mill 0.11.10")
trait CrossSbtModuleTests extends SbtModuleTests {
trait CrossSbtModuleTests extends SbtTests {
override def millSourcePath = outer.millSourcePath
override def sources = T.sources {
super.sources() ++ scalaVersionDirectoryNames.map(s =>
PathRef(millSourcePath / "src" / "test" / s"scala-$s")
)
}
}
@deprecated("Use CrossTests instead", since = "Mill after 0.12.0-RC1")
trait Tests extends CrossSbtModuleTests
}
10 changes: 8 additions & 2 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ trait JavaModule
with BspModule
with SemanticDbJavaModule { outer =>

def zincWorker: ModuleRef[ZincWorkerModule] = super.zincWorker
override def zincWorker: ModuleRef[ZincWorkerModule] = super.zincWorker
@nowarn
type JavaTests = JavaModuleTests
@deprecated("Use JavaTests instead", since = "Mill 0.11.10")
trait JavaModuleTests extends JavaModule with TestModule {
Expand Down Expand Up @@ -160,6 +161,11 @@ trait JavaModule
*/
def javacOptions: T[Seq[String]] = T { Seq.empty[String] }

/**
* Additional options for the java compiled derived from other module settings.
lefou marked this conversation as resolved.
Show resolved Hide resolved
*/
def managedJavacOptions: T[Seq[String]] = T { Seq.empty[String] }

/**
* The direct dependencies of this module.
* This is meant to be overridden to add dependencies.
Expand Down Expand Up @@ -422,7 +428,7 @@ trait JavaModule
upstreamCompileOutput = upstreamCompileOutput(),
sources = allSourceFiles().map(_.path),
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions(),
javacOptions = javacOptions() ++ managedJavacOptions(),
reporter = T.reporter.apply(hashCode),
reportCachedProblems = zincReportCachedProblems(),
incrementalCompilation = zincIncrementalCompilation()
Expand Down
5 changes: 4 additions & 1 deletion scalalib/src/mill/scalalib/MavenModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mill.scalalib

import mill.T

import scala.annotation.nowarn

/**
* A [[JavaModule]] with a Maven compatible directory layout.
*
Expand All @@ -16,9 +18,10 @@ trait MavenModule extends JavaModule { outer =>
millSourcePath / "src" / "main" / "resources"
}

@nowarn
type MavenTests = MavenModuleTests
@deprecated("Use JavaTests instead", since = "Mill 0.11.10")
trait MavenModuleTests extends JavaModuleTests {
trait MavenModuleTests extends JavaTests {
override def millSourcePath = outer.millSourcePath
override def intellijModulePath: os.Path = outer.millSourcePath / "src" / "test"

Expand Down
3 changes: 3 additions & 0 deletions scalalib/src/mill/scalalib/SbtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mill.scalalib

import mill.T

import scala.annotation.nowarn

/**
* A [[ScalaModule]] with sbt compatible directory layout.
*/
Expand All @@ -12,6 +14,7 @@ trait SbtModule extends ScalaModule with MavenModule {
millSourcePath / "src" / "main" / "java"
)

@nowarn
type SbtTests = SbtModuleTests
@deprecated("Use SbtTests instead", since = "Mill 0.11.10")
trait SbtModuleTests extends ScalaTests with MavenTests {
Expand Down
4 changes: 2 additions & 2 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
@deprecated("use ScalaTests", "0.11.0")
type ScalaModuleTests = ScalaTests

trait ScalaTests extends JavaModuleTests with ScalaModule {
trait ScalaTests extends JavaTests with ScalaModule {
override def scalaOrganization: Target[String] = outer.scalaOrganization()
override def scalaVersion: Target[String] = outer.scalaVersion()
override def scalacPluginIvyDeps: Target[Agg[Dep]] = outer.scalacPluginIvyDeps()
Expand Down Expand Up @@ -279,7 +279,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
upstreamCompileOutput = upstreamCompileOutput(),
sources = allSourceFiles().map(_.path),
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions(),
javacOptions = javacOptions() ++ managedJavacOptions(),
scalaVersion = sv,
scalaOrganization = scalaOrganization(),
scalacOptions = allScalacOptions(),
Expand Down
6 changes: 5 additions & 1 deletion scalalib/src/mill/scalalib/SemanticDbJavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait SemanticDbJavaModule extends CoursierModule {
def compile: T[mill.scalalib.api.CompilationResult]
def bspBuildTarget: BspBuildTarget
def javacOptions: T[Seq[String]]
def managedJavacOptions: T[Seq[String]]
def compileClasspath: T[Agg[PathRef]]

def semanticDbVersion: T[String] = T.input {
Expand Down Expand Up @@ -98,7 +99,10 @@ trait SemanticDbJavaModule extends CoursierModule {
}

def semanticDbData: T[PathRef] = T.persistent {
val javacOpts = SemanticDbJavaModule.javacOptionsTask(javacOptions(), semanticDbJavaVersion())
val javacOpts = SemanticDbJavaModule.javacOptionsTask(
javacOptions() ++ managedJavacOptions(),
semanticDbJavaVersion()
)

// we currently assume, we don't do incremental java compilation
os.remove.all(T.dest / "classes")
Expand Down
6 changes: 3 additions & 3 deletions scalalib/test/src/mill/scalalib/HelloJavaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ object HelloJavaTests extends TestSuite {
object HelloJava extends TestBaseModule {
object core extends JavaModule {
override def docJarUseArgsFile = false
object test extends JavaModuleTests with TestModule.Junit4
object test extends JavaTests with TestModule.Junit4
}
object app extends JavaModule {
override def docJarUseArgsFile = true
override def moduleDeps = Seq(core)
object test extends JavaModuleTests with TestModule.Junit4
object testJunit5 extends JavaModuleTests with TestModule.Junit5 {
object test extends JavaTests with TestModule.Junit4
object testJunit5 extends JavaTests with TestModule.Junit5 {
override def ivyDeps: T[Agg[Dep]] = T {
super.ivyDeps() ++ Agg(ivy"org.junit.jupiter:junit-jupiter-params:5.7.0")
}
Expand Down
Loading