sbt submit gives "not a valid command" error - scala

Trying to submit my assignments. Looks easy from the demo, but receiving weird error. SBT version is correct. What may be wrong?
> sbt-version
[info] 0.12.4
> submit
[error] Not a valid command: submit (similar: set)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: submit

You need to be using the code package for the course downloaded from the Coursera course web site, otherwise there will be no submit command available as it's not a built-in of SBT or Scala or anything. This is also covered by the tutorial video lecture, and you will be able to obtain the link from the course site.
Also, you need to provide your e-mail address and submission key (which you can obtain from the course web site) as parameters to the submit command.

yes, I watched all the videos... but imported the example incorrectly :)
To correctly import the example, you need to run sbt in the folder with the build.sbt file. In my case, the scalatest version was not found. To fix, it could be updated to (in CommonBuild.scala):
lazy val scalaTestDependency = "org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test

Related

Can scalameter be imported to scala3 projects (and how)?

I tried to use scalameter 0.21 (and some other versions) with scala 3.1.2.
I added some configurations from the scalameter web-page in my build.sbt file and tried serveral things to make this work, but sbt was not able to find the desired packages.
I would have concluded that scalameter is simply not available for scala3, but there is a question here where somebody somehow got it to work.
The problem seemed to bee that sbt added a 3 in all the sources, as in:
https://repo1.maven.org/maven2/com/storm-enroute/scalameter_3/0.21/scalameter_3-0.21.pom
but the path with scalameter_3 did not exist. If I change the scalaversion to 2.13.8, sbt is able to download all the nesessary files without error. Starting with scala version 3.0.0 the problem exists.
If somebody could post a build.sbt file where scalameter and scala3 are used together, I would apreciate it.
Otherwise, if somebody knows a different library for benchmarking with scala 3...
Thanks very much
As #maxkar mentioned, using crossVersion should do the job:
("com.storm-enroute" %% "scalameter" % "0.21").cross(CrossVersion.for3Use2_13) % Test
However, doing so, you may encounter a problem with conflicting dependencies, e.g.:
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(...
[error] org.scala-lang.modules:scala-xml _2.13, _3
In such a case, dependency exclusion, as described in sbt documentation, should solve the issue:
("com.storm-enroute" %% "scalameter" % "0.21").cross(CrossVersion.for3Use2_13) % Test exclude("org.scala-lang.modules", "scala-xml_2.13")
I'm not sure if this cannot backfire in certain situations, but it worked perfectly in my case.

sbt new scala/scalatest.g8 fails on TransportException

When I try to create the ScalaTest example with this command:
sbt new scala/scalatest-example.g8 fails on TransportException
I get the following:
[info] Set current project to scala (in build file:/Users/chasrmartin/Dropbox/Etudes/Scala/)
[error] org.eclipse.jgit.api.errors.TransportException: git#github.com:scala/scalatest-example.g8.git: Auth fail
[error] at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:139)
[error] at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:193)
I've tried several workarounds from around the next (eg this SO question) to no avail. It would seem this has to be a simple problem, I got this command from a beginners tutorial.
Update
I got this command from https://www.scala-lang.org/documentation/getting-started-sbt-track/testing-scala-with-sbt-on-the-command-line.html
This project doesn't seems to exists anymore.
Instead I would prefer to run with the normal scala-seed.g8
> sbt new scala/scala-seed.g8
And add the test classes manually.
This is an equivalent tutorial with the same classes and tests.
The scala seed template already comes with the structure you want, with the test dependency. You can run sbt test normally.

Scala 2.2.4 with Secure Social and Facebook login

I've taken over a project which uses SecureSocial 2.1.4 and is running Scala 2.2.4
I looked at updating, and decided that as the app is in such disrepair and hasn't been updated in so long, I'd just do a rebuild in a different language (I've done almost no Scala).
Today, it looks like an update to the Facebook API has broken logins.
I'm trying to figure out the quickest path to getting logins back, but can't figure out what is the best version to update to, and how to get that to work nicely with the simplest version of scala.
In the Build.scala, it shows
"ws.securesocial" %% "securesocial" % "2.1.4",
"com.typesafe" %% "play-plugins-mailer" % "2.2" exclude("org.scala-stm", "scala-stm_2.10.0"),
When I try to update to 2.10, I get
[warn] :: ws.securesocial#securesocial_2.10;2.10: not found
[warn] :: com.typesafe#play-plugins-mailer_2.10;2.2: not found
In play.plugins, it has
1500:com.typesafe.plugin.CommonsMailerPlugin
9994:securesocial.core.DefaultAuthenticatorStore
9995:securesocial.core.DefaultIdGenerator
I did manage to get a build using
"ws.securesocial" %% "securesocial" % "M3.0-M1"
When I run the app using securesocial 2.1.4 and try to login, the only error I see to get is
Unable to log user in. An exception was thrown
[error] application - Unable to log user in. An exception was thrown
securesocial.core.AuthenticationException: null
at securesocial.core.OAuth2Provider.doAuth(OAuth2Provider.scala:117) ~[securesocial_2.10-2.1.4.jar:2.1.4]
at securesocial.core.IdentityProvider.authenticate(IdentityProvider.scala:75) ~[securesocial_2.10-2.1.4.jar:2.1.4]
at securesocial.controllers.ProviderController$$anonfun$handleAuth$1.apply(ProviderController.scala:92) [securesocial_2.10-2.1.4.jar:2.1.4]
at securesocial.controllers.ProviderController$$anonfun$handleAuth$1.apply(ProviderController.scala:88) [securesocial_2.10-2.1.4.jar:2.1.4]
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:221) [play_2.10-2.2.4.jar:2.2.4]
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:220) [play_2.10-2.2.4.jar:2.2.4]
The ultimate solution would be if I could update my model to work with the new facebook changes to the API
-------------- UPDATE ---------------
Doing more research, it appears the issue may be that Facebook is returning valid JSON tokens rather than url encoded as they had been before
https://developers.facebook.com/docs/apps/changelog#v2_3
Now, just trying to figure out how to update that in scala or secure_social
Since you are using 2.1.4 I suggest you create a new Facebook provider that does not override the buildInfo method in OAuth2Provider and register that instead of the built in one.
That should get you going quite fast.

Coursera Scala SBT submission issues

I am a current student at the EPFL functional programming in SCALA course on coursera.
I have successfully passed the first course by submitting my assignments via sbt with no issues until now.
When I tried to submit the 'calculator' assignment with my generated token, I get error messages like
Set current project to src (in build
file:/C:/Users/user/Desktop/cousera%20class/calculator/calculator/src/)
submit [error] Not a valid command: submit (similar: set) [error] Not a valid project ID: submit [error] Expected ':' (if selecting a
configuration) [error] Not a valid key: submit [error] submit
Please who's faced this challenge in the past? I need help
Here is what I have done.
Ignored all the setup tutorials that are there.
Installed sbt on my Ubuntu using apt.
Imported the example project here.
Went into following the steps there.
Submitted using sbt then submit myemail#email.com [token].
Hope that can be helpful.
Just in case this helps anybody else, I had the same problem. I tried running sbt submit {my.email#domain.com} {token} from the project root, but that didn't work. Running sbt by itself entered an interpreter type thing, which accepts commands, and running submit {my.email#domain.com} {token} from there worked.
Very strange.

ScalaTest errors on assert and test in Intellij

I am fairly new to Scala and Intellij and brand new to ScalaTest. I have set up Intellij 14 and Scala 2.11.4 with the latest Scala plugin and everything works fine. I then tried to introduce ScalaTest and I am very confused. I downloaded the latest version of ScalaTest (scalatest_2.11-2.2.1.jar) from scalatest.org. I went into my project structure and selected "Modules", clicked the green plus sign and added scalatest_2.11-2.2.1.jar. All went well and I can see the scalatest jar in External Libraries in my project. When I created my first test it imported org.scalatest.Funsuite and the class extended FunSuite and all was well. I then tried a very simple test that I copied from the Internet.
import org.scalatest.FunSuite
class MyTest extends FunSuite {
test("this is a test") {
assert(true)
}
}
I get 2 errors. It can not resolve the "assert" reference with that signature and for the "test" method it says unspecified value parameters Seq[Tag]: () => BoxedUnit.
I can see other method signatures for "assert" and "test" but I can not use the most basic ones.
Thanks for any help
While I didn't get exactly the same error messages, I had similar overall problems until I realized that you need two more JARs to use ScalaTest successfully: scala-reflect-2.11.4.jar and scala-xml-2.11-1.0.2.jar.
If you insist on doing this by hand you should also make sure that you have your tests in a directory that is marked as a "tests" directory -- so is highlighted in green: you can achieve this on the same "Modules" tab, but in the "Sources" sub-tab rather than "Dependencies". You also need to check that in the "Scope" column of the "Dependencies" sub-tab, the jars you added are marked as "Test" rather than "Compile".
If, on the other hand, you create an SBT project in IntelliJ rather than a regular Scala project, you could just add the following to your build.sbt:
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1" % "test"
Re-import the build.sbt when prompted, then you can start writing and running tests: all the dependencies and test directories are set up correctly and it all "just works". I just created an empty project this way and ran your example. It took about a minute from beginning to end.
Obviously you're facing a trade-off between managing JARs by hand and learning yet another tool, but at this point learning the very basics of SBT may be worth your while.