How can an SBT plugin depend on another plugin - sbt

I want to write a plugin "MyPlugin" that depends on the another plugin
("io.spray" %% "sbt-twirl" % "0.6.0").
Simply adding sbt-twirl in libraryDependencies will not work,
because plugins get published with a different path scheme
than standard libraries.
I also cannot declare sbt-twirl as a plugin dependency to MyPlugin
project, because MyPlugin does not use the sbt-twirl directly,
it is the project using MyPlugin that will indirectly use it.
MyPlugin provides a task that is meant to be run after sbt-twirl
has generated it's sources (in sourceManaged) and after compilation.
A simple but non ideal solution would be to require the project using
MyPlugin to also declare sbt-twirl as a plugin dependency, but it is not
DRY because the two plugins will be sharing some settings (directories, versions, etc),
and they will have to be repeated and compatible.

It should be the same definition as for using a plugin as a plugin, except that it goes in build.sbt or project/Build.scala instead of project/plugins.sbt:
addSbtPlugin("io.spray" % "sbt-twirl" % "0.6.0")

Related

How can I add a compiler plugin only to Test in sbt?

I have a compiler plugin I've been adding to projects like this in my build.sbt:
addCompilerPlugin("co.blocke" %% "dotty-reflection" % "0.2.0")
In this case, I don't want the compiler plugin active during main compile, but I DO want it active during test compile. How can I specify this?

where did 'resolved.xml.xml` file disappear?

after changing the sbt.version in the build.properties to 1.3.x, i've found out that the resolved.xml.xml files, which were created after running sbt compile are not created anymore. i'm using those files to re-create the project's structure and dependencies tree.
is there any equivalent to those files in the new SBT version?
yes, i'm familiar with sbt-dependency-graph plugin, but i want to avoid using external solution.
You can disable the integrated coursier to get the old behaviour back:
ThisBuild / useCoursier := false

find sbt plugins versions

I am using some sbt plugins on a project and I would like to know which are their versions from sbt console.
I can type plugins which list the plugins but do not present their versions.
I want to do it from the sbt console, I do not want to inspect some plugins.sbt file or similar somewhere.
When you use plugins command, you see references to the plugins as they are defined in the Scala code. A single artifact can contain many plugins. Those artifacts with plugins have versions and here's how you can see them.
First load the metaproject: reload plugins
Then check dependencies: libraryDependencies
Go back to your project: reload return
You can define an alias for this in your ~/.sbt/<version>/global.sbt:
addCommandAlias("pluginsVersions", "; reload plugins ; libraryDependencies ; reload return")
It's not perfect, the output is noisy and not formatted nicely, but it's something you can get out of the box.

xsbt-web multi-module project: package some modules to jars, others to wars

I'm using sbt 0.13.8 and xsbt-web-plugin 2.0.3
I have a multi-module sbt project. When packaged, one of the modules should be in the form of a war file. All of the others in jar files.
When I add the xsbt-web plugin, packaging generates jars and wars for all modules. How can I tell the xsbt-web plugin to apply itself only to the module that should be packaged as a war?
I've already found one solution, which is to mutate the packagedArtifacts list for each non-war module:
packagedArtifacts <<= packagedArtifacts map { as => as.filter(_._1.`type` != "war") }
However, this is a non-local change which I would have to apply to each new non-war module that I (or a team member) might create.
I do not consider this a duplicate of the StackOverflow issue How to “package” some modules to jars and others to wars in multi-module build with single task? since I am not using assembly.
Note that the jars for the jar modules and the wars for the war modules, which are currently being generated, work splendidly. I'm only trying to avoid the situation where somebody tries to deploy a war that was meant to be a jar.
This was a bug in version 2.0.3 -- thanks for discovering it! I've fixed it in 2.0.4.
To enable .war file publishing for a single module in a multi-module project:
Add xsbt-web-plugin in project/plugins.sbt
Enable the WarPlugin plugin in [webproject]/build.sbt
project/plugins.sbt:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.0.4")
[webproject]/build.sbt:
enablePlugins(WarPlugin)
You can find a full example of this at https://earldouglas.com/ext/stackoverflow.com/questions/31683637/

qmake: how to build dependencies without TEMPLATE=subdirs

TL;DR: Is there a way to build a target from a .pro file in a different project without using TEMPLATE = subdirs?
Long version:
I have a complex project (mycomplexproject) with lots of subirs and *.pro files. One module (moduleA) depends on a DLL built in a different project outside of this project (anotherproject). Because reasons I cannot create a *.pro file with a subdirs template in somerootdir.
Is there a way to add a dependency in moduleA.pro so anotherproject is built whenever moduleA is built and anotherproject.dll does not exist without having to create a *.pro file in somerootdir?
somerootdir/
anotherproject/ // must be independent of mycomplexproject
anotherproject.pro
lib/
anotherproject.dll // the result of building anotherproject
[...]
mycomplexproject/
core/
core.pro
modules/
moduleA/
moduleA.pro // depends on anotherproject.dll built from anotherproject.pro
moduleB/
moduleB.pro
modules.pro // uses subdir template
mycomplexproject.pro // uses subdir template
P.S.: moduleA is only built under certain circumstances, and building anotherproject is only necessary if moduleAis built.

Resources