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

support sbt #291

Closed
He-Pin opened this issue Jan 30, 2015 · 11 comments
Closed

support sbt #291

He-Pin opened this issue Jan 30, 2015 · 11 comments

Comments

@He-Pin
Copy link

He-Pin commented Jan 30, 2015

there is no integration with sbt

@cushon
Copy link
Collaborator

cushon commented Feb 3, 2015

We'd like to support as many build systems as possible. But we have limited time, and the ones we already support have been a bit neglected lately. It may be a while before sbt happens.

Feel free to send us a patch, though!

@PromanSEW
Copy link

Any updates here?

@ronshapiro
Copy link
Contributor

In it's current state, supporting Scala code is likely to be extremely difficult. Error Prone is heavily reliant on javac's AST. Supporting other JVM languages would require a common API for ASTs and type systems. Not impossible, but definitely a massive shift from what EP currently is doing.

@PromanSEW
Copy link

PromanSEW commented Jun 11, 2018

@ronshapiro
I want use Error-Prone in Play Framework project with Java as main language.
IntelliJ IDEA plugin use old version of Error-prone, and I can't override it.

@tbroyer
Copy link
Contributor

tbroyer commented Jun 11, 2018

Using JDK 9+ and a recent Error Prone, it should be possible to use Error Prone as a Javac plugin: add com.google.errorprone:error_prone_core (you can exclude com.google.errorprone:javac from the transitive dependencies) to the -processorpath and pass an additional -Xplugin:ErrorProne argument (possibly followed by Error Prone-specific arguments, space-separated, in the same argument). No requirement for build tool integration. See http://errorprone.info/docs/installation#java-9

@He-Pin
Copy link
Author

He-Pin commented Oct 13, 2018

@ronshapiro I mean as a sbt plugin:)

@cushon
Copy link
Collaborator

cushon commented Oct 13, 2018

Assuming sbt is using javac to compile Java, it should be possible to enable Error Prone using the -Xplugin integration @tbroyer described. We don't have any plans to create a different integration for sbt at this time.

@cushon cushon closed this as completed Oct 13, 2018
@mikavilpas
Copy link

mikavilpas commented Nov 13, 2020

Sorry to dig up an old issue, but I managed to do exactly what was suggested and wrapped it to a global sbt plugin. The code might be useful for someone who wants to try this out with sbt:

// This file is $HOME/.sbt/1.0/plugins/ErrorProne.scala
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin

// put these files into ./errorprone/
// https://oss.sonatype.org/content/repositories/snapshots/com/google/errorprone/error_prone_core/2.4.1-SNAPSHOT/error_prone_core-2.4.1-20201112.221044-130-with-dependencies.jar
// https://repo1.maven.org/maven2/org/checkerframework/dataflow-shaded/3.1.2/dataflow-shaded-3.1.2.jar
// https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/jFormatString-3.0.0.jar

object ErrorProne extends AutoPlugin {
  override def trigger               = allRequirements
  override def requires: sbt.Plugins = JvmPlugin

  override def projectSettings = Seq(
    javacOptions ++= Seq(
      "-XDcompilePolicy=simple",
      "-processorpath", dependencyFiles,
      "-Xplugin:ErrorProne"
    )
  )

  private def dependencyFiles = {
    val home: String = sys.env.get("HOME").get
    def file(name: String) = s"${home}/.sbt/1.0/plugins/errorprone/$name"

    val files = List(file("error_prone_core-2.4.1-20201112.221044-130-with-dependencies.jar"),
                     file("dataflow-shaded-3.1.2.jar"),
                     file("jFormatString-3.0.0.jar"))

    val filestring = files.mkString(":")

    println(s"Using errorprone libs from $filestring")
    filestring
  }
}

@pan3793
Copy link

pan3793 commented Mar 26, 2024

@mikavilpas is it possible to write as a project-level plugin?

@mikavilpas
Copy link

Sorry but I have not worked in scala for a couple of years now, and I don't remember much about it.

@pan3793
Copy link

pan3793 commented Mar 27, 2024

@mikavilpas alright. anyway, thanks for providing such an example

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

No branches or pull requests

7 participants