SBT AutoPlugins conflict that shouldn't be there - scala

I have a sbt project using FlyWay. It's disabled in most projects because we're only running the evolutions from a specific project.
So I have something like this:
lazy val master = project
.disablePlugins(FlywayPlugin)
.aggregate(common)
.dependsOn(common)
The project works fine. It compiles, works, tests pass, etc.
Now I want to add Twirl, so I do this (in addition to plugins.sbt of course):
lazy val master = project
.enablePlugins(SbtTwirl)
.disablePlugins(FlywayPlugin)
.aggregate(common)
.dependsOn(common)
And I end up with this error:
[error] sbt.AutoPluginException: Error determining plugins for project 'master' in /opt/app/master:
[error] Contradiction in selected plugins. These plugins were both included and excluded: org.flywaydb.sbt.FlywayPlugin
[error] Use 'last' for the full log.
Which I don't really understand because I didn't change anything about FlyWay.
What could cause that?

This is a known problem. FlywayPlugin gets automatically enabled on all (sub)projects and when you try to disable it, it causes the conflict.
See sbt/sbt#1926. Citing #jsuereth:
Yeah, this is a known issue in our logic system (and the translation of enablement/disablement into it). I'm working on a mechanism to fix it.
PRs welcome if you have time.
There is also an open issue in the Flyway repository: flyway/flyway#1329 which suggests not to enable it automatically. But so far there is no solution or a workaround there.

Related

Scala Play Rest service cannot find Controllers in routes file [Play 2.6, Scala]

I have recently revisited a project I have not worked on in over a year. Yesterday I was able to successfully run the REST service with no problems. Today while I was refactoring the location of certain controllers in this project I started to encounter errors related to controllers could not be found within a given package.
My routes file that looks like this:
UserController is defined as such:
However; when trying to compile this project, I receive a list of errors like: (redacted most, only included one controller for sample)
type UserController is not a member of package com.jkdev.controllers
[error] POST /users com.jkdev.controllers.UserController.createUser
Additionally, my Binders are no longer being detected by the routes file as well, so I am seeing errors like: [error] /Users/...../Developer/cashflows/metadata/conf/routes: object binders is not a member of package com.jkdev.
Like I mentioned, yesterday this was working, so I tried reverting to that commit and rebuilding, but this issue persists.
I have attempted to delete all target directories and recompile, ran sbt clean; cleanFiles. All of which provided nothing of value.
Overall this feels like a build error; but I changed nothing about the build file so I have no idea where to look next
The problem was:
I updated the intelliJ SBT preferences to use sbt shell for all builds,tests,runs, etc.
After deleting all of the ./target directories, doing SBT compile and run did not reproduce the target directories for my projects.
After updating IJ SBT preferences to not use SBT shell for builds; I was able to re-compile w/ IJ and reproduce the target directories.
Doing sbt run afterwards successfully launches the server.

How to use SBT's externalPom() command

I have a Maven POM file that the deployment engineers need to deploy the system in the enterprise. I have developers using SBT for a Scala project. They use SBT targets that just aren't supported in Maven. We'd like to use the Maven POM file to define the dependencies, slurp in those dependencies in SBT, and define SBT development targets there.
According to the SBT documentation, the externalPom() command is the way to do that. But even with the simplest POM file (two developers have tried this with two different simple POM files that defined different dependencies), the externalPom() command seems to half work. The SBT targets clearly recognize the dependency defined in the POM, but can't resolve it. This error arises:
Cannot add dependency 'commons-collections#commons-collections;3.2.2'
to configuration 'default' of module
default#maven-sbt$sources_javadoc;0.1-SNAPSHOT because this
configuration doesn't exist!
When the externalPom() command is commented out and the equivalent dependency added directly in the build.sbt file everything goes swimmingly. The dependency comes directly from Maven Central in both cases; one from copying the dependency from the Maven tab and one from copying the dependency from the SBT tab. Once again, two developers are seeing exactly the same thing, from two different dependencies. The thing that's common is that both developers have reduced the build.sbt file down to a single statement. In the "slurp from POM" case, that statement is externalPom(). In the "plain old SBT" case, that statement is the dependency copied from Maven Central. The POM file is a dependency list with a single dependency (as simple as we can make it and still test externalPom()).
We suspect that we need something else in the build.sbt to make the externalPom() command work but we don't know what it is. Any help with that would be greatly appreciated.
I did some experimentation with this, and was able to replicate your error in my experiments.
I'm still a bit of a Scala / SBT newbie, but I created a build.sbt file that looks like so:
val Default = config("default")
lazy val root = (project in file(".")).
configs(Default).
settings(
externalPom()
)
This did compile for me!
One non-obvious catch: I had to make sure to include the scala-library in my POM file as a dependency

SBT multi-project build classpath problems

I have a SBT project I'm trying to separate into a multi-project build.
For some reason, there are a few tests I can't get to work when running the tests from the root build.
These tests use Akka, and it looks something is wrong with the class path - the config is not loaded properly and I get this error:
[error] com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka' (SimpleConfig.java:152)
The dependency is configured for the sub-project, and works fine when I run the tests from within the project itself, and not from the root build.
Does someone know how can I get this to work?
Thanks for your help
Just been having this problem myself, we managed to solve it by enabling forking in the project:
ThisBuild / fork := true

Intellij 15.0.5 issue with SBT and Scala project

I am trying to set up IntelliJ for my Scala development after hearing how much better it is compared to alternatives. But I can't seem to run anything. The problems I'm facing are as follows:
As soon as the project is created, the console shows SBT failures
My build.sbt file shows red wiggles (compile time errors)
The confusing part is that opening the "SBT Console" view from within the IDE works fine.
The error trace is something along the lines of:
[info] Loading project definition from D:\workspaces\intellij\scala\untitled\project
java.io.IOException: The filename, directory name or volume label syntax is incorrect
[error] (*:update) java.io.IOException: The filename, directory name or volume label syntax is incorrect
Would anyone please know what can cause this? I have tried deleting the project and creating a new one but the problem still persists.
UPDATE
Just had a look at .sbt\boot\update.log and something seems fishy. Is it just me or the sbt.ivy.home is completely borked?
impossible to define new type: class not found: org.apache.ivy.osgi.obr.OBRResolver in [] nor Ivy classloader
impossible to define glob matcher: org.apache.ivy.plugins.matcher.GlobPatternMatcher was not found.
setting 'jline.esc.timeout' to '0'
setting 'sbt.ivy.home' to 'D:\software\installed\sbt\.ivy2 -Divy.home=D:\software\installed\sbt\.ivy2'
setting 'java.runtime.name' to 'Java(TM) SE Runtime Environment'
I have finally managed to hunt down the root cause. The errors were due to rogue environment variables set in my profile related to SBT (specifically SBT_OPTS). Once I deleted all of them and started with a clean slate, things started working on expected.

IntelliJ Idea sbt managed source file

I am using sbt-buildinfo plugin that generates Scala source from my build definitions, allowing me to reference project name, version, etc. from my Scala code.
It does this by generating a file BuiltInfo.scala with the following contents:
package hello
case object BuildInfo {
val name = "helloworld"
val version = "0.1-SNAPSHOT"
val scalaVersion = "2.10.3"
val sbtVersion = "0.13.2"
}
in
target/scala-2.10/src_managed/main/sbt-buildinfo/BuildInfo.scala.
Everything compiles and I can reference those vals.
However, IntelliJ Idea doesn't recognize BuildInfo.scala as a managed source file, so that it would stop showing me errors. Any idea how to do that?
Thanks!
Grega, are you working in a Play Framework project? Or do you have any SBT sub-projects? I don't have a complete answer, but may have a lead.
This same problem shows up in my IDEA projects when using sbt-buildinfo and sbt-scalaxb. Frustratingly, it has worked intermittently—usually after lots of tinkering around, but inexplicably stops.
I wound up digging a bit deeper (and eventually issued bug report SCL-7182 to JetBrains), and noticed the root cause was having a sub-project. When present, IDEA doesn't correctly identify src_managed for the root project, but does for the sub-project.
A work-around, for now, is to manually add the correct src_managed directory to your project's sources using the Project Structure dialog.
For reference, I'm running version 0.38.437 of the Scala plugin on IntelliJ IDEA 13.1.3.