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

SBT plugin? #351

Closed
lloydmeta opened this issue Mar 6, 2016 · 9 comments
Closed

SBT plugin? #351

lloydmeta opened this issue Mar 6, 2016 · 9 comments
Assignees

Comments

@lloydmeta
Copy link
Member

I wrote a simple SBT plugin to make JavaCV easier to set up (adds all the dependencies, adds maven-plugin to the classpathTypes, and sets up the classifier stuff too), essentially turning into a 1 liner:

In project/plugins.sbt, add

addSbtPlugin("com.beachape" % "sbt-opencv" % "1.2")

You can find it here: https://github.com/lloydmeta/sbt-opencv

Was wondering if you were interested in putting it in the SBT set up section. If so I can issue a PR.

@saudet
Copy link
Member

saudet commented Mar 6, 2016

Cool! Could this be extended easily to more than just OpenCV or JavaCV?

I'm assigning @jpsacha because he's our resident Scala expert :) Comments?

I'm also wondering, should we have a separate repo for Scala related stuff? How should it be structured? That is, if we could do something that can generalize to all libraries...

@saudet
Copy link
Member

saudet commented Mar 6, 2016

For now though, sure please do put up a wiki page about this. Write access should be available to all!

@lloydmeta
Copy link
Member Author

The plugin I wrote mainly has the following merits:

  • Single liner
  • Takes care of injecting the proper libraries into the build
  • Takes care of classifier (ie make it available to the build definition)
  • Takes care of adding maven-plugins to classifierTypes
  • Takes care of setting autoCompilerPlugins := true

I think to generalise (I assume you mean generalising it to other JavaCPP-family projects, included JavaCPP) and keep most of those benefits, the following would be the easiest and flexible

  • Factor out the JavaCPP parts of sbt-opencv into sbt-javacpp, taking care of the common things like adding JavaCPP as a dependency
  • Have sbt-opencv depend on sbt-javacpp and inject JavaCV-specific libraries as well as classifier-specifiers for required CPP libs. Other JavaCPP-based things can follow the same pattern)

@jpsacha
Copy link
Member

jpsacha commented Mar 6, 2016

@lloydmeta Looks interesting. I had only a brief look at the source code of the sbt-javacp plugin. Noticed that it duplicates javacpp code for platform detection. That can be avoided. You can directly use javacpp for that:

val platform = org.bytedeco.javacpp.Loader.getPlatform

like here. You will just need to add plugin dependency on javacpp:

classpathTypes += "maven-plugin"
libraryDependencies += "org.bytedeco" % "javacpp" % "1.1"

@saudet
Copy link
Member

saudet commented Mar 7, 2016

@lloydmeta So, is it something that would need to be done for each project? Or is there a possibility to create something that could automatically include native dependencies (using the classifier there), like it's possible with Maven?

@saudet
Copy link
Member

saudet commented Mar 7, 2016

That reminds me, @jpsacha did post something related to that at #123 (comment) . So, it looks like we can have a function that the user would call and that basically adds native depencencies for the libraries passed as arguments. That sounds like something that could be done once, and would work for any JavaCPP-related projects, not just OpenCV. Thoughts? Does it really work? We can't really add dependencies that way with Maven, but if it works with sbt, sounds like that would be great.

BTW, thanks for the input @jpsacha!

@lloydmeta
Copy link
Member Author

@jpsacha Good idea, but it isn't quite that simple because you can't seem to manage the SBT classpathTypes of a project that pulls in your plugin. I asked this question on SO a while ago and since no one answered, gave up, thus the duplication.

@saudet I see what you mean now. I think it's a good idea, but I'm not sure about its feasibility. If my experience with SBT has taught me anything, it sounds somewhat tricky because I think it would require us to look up library dependencies even before SBT itself has had a chance to resolve them. The other part is that it would no longer be a one liner (one line to add the plugin, another to add that setting in the project build definition), which isn't terrible.

EDIT: For now, I've added a javaCppPresetDependency helper method in SBT-JavaCPP, which adds native dependencies for the JavaCPP preset library name you pass in, which gets us part of the way there. Its usage is as follows:

// in build.sbt
JavaCppPlugin.javaCppPresetDependency("opencv")

@jpsacha
Copy link
Member

jpsacha commented Mar 7, 2016

@saudet Yes, native dependencies could be automatically added. The code in the issue 123 comment was taken out of my actual project. You will need to list only the library names and versions.

As mentioned in the comment, it maybe possible to automatically scan all javacv dependencies and add native dependencies wherever needed, though I did not have chance to look into it in more details.

@lloydmeta
Copy link
Member Author

Yeah, to be clear, automatically scanning all javacv dependencies then including and changing those to include native dependencies for JavaCPP presets is the part I wanted to mention was tricky.

Allowing you to easily add any preset with native dependencies is done now in sbt-javacpp (see my edited comment)

@saudet saudet closed this as completed Mar 27, 2016
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

3 participants