Skip to content

Commit

Permalink
Documentation and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Sep 8, 2024
1 parent 060b3dc commit 4369e9d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions contrib/errorprone/readme.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
= Mill ErrorProne Plugin

https://errorprone.info/index[Error Prone] augments the Java compiler's type checker and detect common mistakes at compile time.

You just need to mix the `ErrorProneModule` into your `JavaModule` and it will automatically run with every compilation.

.`build.mill.sc`: Enable `ErrorProne` in a module
[source,scala]
----
package build
import mill._, scalalib._
import $ivy.`com.lihaoyi::mill-contrib-errorprone:`
import mill.contrib.errorprone.ErrorProneModule
object foo extends JavaModule with ErrorProneModule {
}
----

== Configuration

The following configuration options exist:

`def errorProneVersion: T[String]`::
The `error-prone` version to use. Defaults to [[BuildInfo.errorProneVersion]], the version used to build and test the module.
Find the latest at https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core[mvnrepository.com]

`def errorProneOptions: T[Seq[String]]`::
Options directly given to the `error-prone` processor.
Those are documented as "flags" at https://errorprone.info/docs/flags
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@ import mill.scalalib.{Dep, DepSyntax, JavaModule}

import java.io.File

/**
* Integrated Error Prone into a [[JavaModule]].
*
* See https://errorprone.info/index
*/
trait ErrorProneModule extends JavaModule {

/** The `error-prone` version to use. Defaults to [[BuildInfo.errorProneVersion]]. */
def errorProneVersion: T[String] = T.input {
BuildInfo.errorProneVersion
}

/**
* The dependencies of the `error-prone` compiler plugin.
*/
def errorProneDeps: T[Agg[Dep]] = T {
Agg(
ivy"com.google.errorprone:error_prone_core:${errorProneVersion()}"
)
}

/**
* The classpath of the `error-prone` compiler plugin.
*/
def errorProneClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task { errorProneDeps().map(bindDependency()) })()
}

/**
* Options used to enable and configure the `eror-prone` plugin in the Java compiler.
*/
def errorProneJavacEnableOptions: T[Seq[String]] = T {
val processorPath = errorProneClasspath().map(_.path).mkString(File.pathSeparator)
val enableOpts = Seq(
Expand All @@ -42,8 +60,16 @@ trait ErrorProneModule extends JavaModule {
java17Options ++ enableOpts
}

/**
* Options directly given to the `error-prone` processor.
*
* Those are documented as "flags" at https://errorprone.info/docs/flags
*/
def errorProneOptions: T[Seq[String]] = T { Seq.empty[String] }

/**
* Appends the [[errorProneJavacEnableOptions]] to the Java compiler options.
*/
override def javacOptions: T[Seq[String]] = T {
val supOpts = super.javacOptions()
val enableOpts = Option
Expand Down

0 comments on commit 4369e9d

Please sign in to comment.