sbt-idea icon indicating copy to clipboard operation
sbt-idea copied to clipboard

Multiproject scenario without dependsOn

Open riedelcastro opened this issue 12 years ago • 4 comments

I have the following setup: One of my sbt projects, A, has a dependency to (the artefact of) another of my sbt projects, B. I do not want to express this dependency using dependsOn in my build file, because I want people to compile A without having to have the project B source code lying around---it should be a regular ivy/maven dependency.

Now I would like to still edit both A and B in the same Intellij project, and essentially have Intellij behave "as if there was a dependsOn" between A and B. That is, when compiling and running A in Intellij it would compile B when needed, and use the product of this compilation in the classpath (as opposed to the published version in the local ivy cache). In other words, I want a Intellij module dependency between A and B.

Is the above possible right now? I have created a simple build file that aggregates A and B using ProjectRef/ProjectRoot objects, and this loads both projects okay. But of course the A->B dependency is not mapped to a "module dependency" within Intellij. I could imagine some hack that checks whether ivy/maven dependencies (their IDs) match those of loaded modules, and if so, create a module dependency. I could create a fork and play around with this idea if you think it's possible and wouldn't terribly break things.

Thanks! Sebastian

riedelcastro avatar Aug 06 '12 10:08 riedelcastro

So you would like something similar to changing libraryDependency into a project reference or dependsOn reference in gen-idea run time? Definitely not possible right now, and at first thought does not sound like a trivial thing to do.

What do you mean by "loaded modules"? You would at least need to tell the plugin where in the filesystem the sbt-project for the dependency can be found and what library dependency you would like it to replace as idea module, right?

Feel free to play around :-)

mpeltonen avatar Aug 10 '12 05:08 mpeltonen

Thanks for your answer!

What do you mean by "loaded modules"?

Say, the modules loaded based on a build file that aggregates a couple ProjectRoot/ProjectRef projects.

You would at least need to tell the plugin where in the filesystem the sbt-project for the dependency can be found and what library dependency you would like it to replace as idea module, right?

I was hoping for a more hacky, less sane solution :) I was thinking that for the modules the project aggregates we have the artefact IDs, and we could match these the with dependency artefact ID. If there is a match, the jar dependency in intellij gets replaced with the corresponding module.

Feel free to play around :-)

Will try to!

riedelcastro avatar Aug 10 '12 08:08 riedelcastro

Okay, that actually wasn't so hard: https://github.com/riedelcastro/sbt-idea. I only tested it on one project, but there it seemed to work. The risk of this replace-lib-by-module hack is that now your sbt compilation and your intellij compilations may give different results (as one uses the ivy dependency and the other the module itself). I think I am fine with that though.

I think this may be useful for others (I find it very useful, and I know some others who do so too), so if you want I can clean it up, make this replacement-hack optional, and get it ready to pull.

Btw, the way I used this is to create a "workspace" sbt project with a couple of RootProject/ProjectRef projects aggregated into the root. Whenever there are library dependencies between these projects, as indicated by matching artifact IDs (org_name_scalaversion_version), these library dependencies are replaced by the corresponding module dependencies.

riedelcastro avatar Aug 10 '12 14:08 riedelcastro

Ok so you need to create an extra sbt project above A and B with the references to the projects for this to work, right?

Sounds a little hackish, yes :) But if you make the replacing optional, then I think I'm ok with it, as I can understand someone else may find this useful too.

mpeltonen avatar Aug 13 '12 11:08 mpeltonen