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

Any way to detect if this launcher is being used? #72

Open
dwijnand opened this issue Jun 26, 2019 · 3 comments
Open

Any way to detect if this launcher is being used? #72

dwijnand opened this issue Jun 26, 2019 · 3 comments

Comments

@dwijnand
Copy link

I keep making the mistake of using this launcher (as it's my default) in lampepfl/dotty and later realising when it breaks.

I was thinking: can I detected if this launcher is being used, say, in the build? Perhaps I can fast-fail the onLoad and avoid myself (and others) the same mistake.

@djspiewak
Copy link

This works!

def detectedCsbt(): Boolean = {
  try {
    val klass = Class.forName("lmcoursier.definitions.ToCoursier$")
    val m = klass.getMethod("project", Class.forName("lmcoursier.definitions.Project"))
    m.getReturnType().getName == "coursier.core.Project"
  } catch {
    case _: Throwable => false
  }
}

if (detectedCsbt())
  addSbtPlugin("io.get-coursier" % "sbt-coursier" % "2.0.0-RC3-3")
else
  Seq()

Specific scenario here is I wanted to stick sbt-coursier into my global plugins, conditional on the use of the relevant launcher. This does the trick.

For posterity, the idea here comes from @dcsobral: try using a Coursier-specific plugin task (in my case, coursierDependencyTree) using the sbt-coursier plugin and the regular launcher, then build the detectedCsbt definition using the specific error which arises, which in this case is a NoSuchMethodError referring to the signature in the above.

@alexarchambault
Copy link
Member

alexarchambault commented Jun 5, 2020

@djspiewak @dcsobral May I ask what makes you prefer coursierDependencyTree over sbt-dependency-graph? Not disrupting users of this key (alongside coursierDependencyInverseTree and coursierWhatDependsOn) is basically the only reason I don't discard sbt-coursier for sbt-lm-coursier. I'm not a big user of either coursierDependencyTree or sbt-dependency-graph, so I'm not sure if I should go ahead or not on that.

@djspiewak
Copy link

Dependency graph is much, much slower and also a lot harder to read. coursierDependencyTree was actually the first reason I started using Coursier, because it's far and away the best tool in the ecosystem for diagnosing weird dependency issues.

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

3 participants