SBT asks for credentials when creating a project - sbt

I am completely new to Scala and SBT. I have downloaded the .tgz archive for SBT 1.3.2, extracted it and added its bin directory to my PATH on Ubuntu 18.04.
I am following the official Getting Started guide, which gives a command to create a simple project. It is supposed to run like that:
$ sbt new sbt/scala-seed.g8
....
Minimum Scala build.
name [My Something Project]: hello
Template applied in ./hello
Instead, it asks me for credentials:
$ sbt new sbt/scala_seed.g8
[info] Set current project to code (in build file:/home/user/code/)
[info] Set current project to code (in build file:/home/user/code/)
Username:
I have no idea what to enter. I can't even try to guess, since I can only enter one character before it asks for a password. If I enter one character again, I get the username prompt again. This is the output after pressing two keys:
$ sbt new sbt/scala_seed.g8
[info] Set current project to code (in build file:/home/user/code/)
[info] Set current project to code (in build file:/home/user/code/)
Username: Password:
Username:
I just want to setup a basic project. What am I doing wrong?

If you get sbt new user/some.g8 asking for the Username: then you know that you have typed the template path e.g. user/some.g8 incorrectly so it doesn't exist as a g8 template.
Please check that you have to correct template path and try again.

Even I got the same error when I tried to create a new project following the instruction from https://docs.scala-lang.org/getting-started/sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html using sbt cli.
I ran the command as below,
sbt new hw/hello-world.g8
Following the above command I was prompted for suername and password. Then I ran it again as
sbt new scala/hello-world.g8
This time the project was successfully created.
Output:
hello-world.g8
[info] welcome to sbt 1.3.13 (Oracle Corporation Java 1.8.0_261)
[info] set current project to scala (in build file:/C:/scala/)
[info] set current project to scala (in build file:/C:/scala/)
A template to demonstrate a minimal Scala application
name [Hello World template]: hello-world
Template applied in C:\scala\.\hello-world
So the hw in the command "sbt new hw/hello-world.g8" is not correct and it has to be only "sbt new scala/hello-world.g8".

In the first, working example you have scala hyphen seed.
$ sbt new sbt/scala-seed.g8
....
In the second non-working example you have scala underscore seed.
$ sbt new sbt/scala_seed.g8
[info] Set current project to code (in build file:/home/user/code/)
[info] Set current project to code (in build file:/home/user/code/)
Username:

Related

SBT Publish Customize Version String/Jar Name

I'm trying to publish some scala code to an artifactory repo, and I want to customize the jarname for the publish target.
When I modify the assembly/assemblyJarName it works when I run sbt assembly but as soon as I run sbt publish the jarname in artifactory doesn't match what I defined.
Why does sbt not use the defined jarname when publishing?
I changed the jarname in assembly/assemblyJarName and I expected the version I put in that value to be uploaded to artifactory.
The jar that ends up in artifactory looks like this: <package_name>_<scala_version>-<package_version>---assembly.jar
I can't figure out how to update the string that's uploaded to artifactory.
When I look at the logs from the CI system I see a message like this:
published pcakage_name_scala_version to https://artifactory.domain.com/artifactory/libs-snapshot-local;build.number=11;build.timestamp=1668632283151/com/org/package_name_scala_version/version_number-SNAPSHOT/package_name_scalaversion-version_number-SNAPSHOT-assembly.jar
So the file that's "uploaded" in the logs doesn't even match that artifat that's in artifactory.
There's some magic happening and it's not clear what

Bitbucket pipelines: The type or namespace name could not be found

I'm hoping someone can help me out. Thanks!
I'm trying to deploy my dotnet core 2.0 API
When I try and build the project with bitbucket pipelines I get multiple errors finding references. It does restore the project successfully.
However the project builds successfully on my laptop.
folder structure:
/API
/Controllers
/Migrations
/Models
/Services
API.csproj
Program.cs
Startup.cs
bitbucket-pipelines.yml
pipelines:
default:
- step:
image: microsoft/dotnet
name: Check if it builds
script:
- cd API
- dotnet build
example error:
Services/MyService.cs(18,29): error CS0246: The type or namespace name 'IRepository<>' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/API/API.csproj]
Note I have the latest version of dotnet, same as I'm using in bitbucket pipelines. I have checked via running dotnet --info
Finally i've figured out what was the cause of this issue. I feel really silly for not figuring this out sooner.
My git repository was somehow setup with ignorecase = true.
I have switched it to false (which will prevent this issue in the future).
This means that I can have two of the same files or folders.
I had renamed a folder to a different case.
My repo had
API/
API.csproj
and
api/
api.csproj
My Mac couldn't allow for both so I only saw one folder and one project on my local machine.
To fix this, I had to git rm -r --cached api
This deleted the duplicate folder
I had the project file as a duplicate as well so used git rm -f api.csproj to remove the file from the repository.
Then git pull to bring those changes into my local master branch.

How dotnet build chooses the output name

First, let me explain the problem that causes this question.
If I create a new project using dotnet new and specifying a random project name with -n arg, then after doing dotnet restore - dotnet build from default bash terminal -> the final output name is always React + .output_type. Like:
/bin/Debug/netcoreapp2.0/React.dll
I don't specify any additional arguments with dotnet commands. And looks like it doesn't matter what type of project to select: I have tried with console and webapi.
But I have found that if I open the project in VS Code and do the same dotnet build command from VS Code terminal (that is also bash) -> the output name is correct and equal to the project_name+.output_type.
So before I thought that output name is always taken from .csproj file name during building. But now it looks like something could override this behavior: different terminals - different env settings, etc.
Cause output name contains React I am blaming the react cli tooling, but this doesn't help me with identifying the reason of name-override.
I did dotnet --info from both terminals and output was the same:
.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/2.0.0/
Thanks to #MartinUllrich, I have found that $TARGETNAME variable overrides the project name. Removing variable fix the problem:
> unset TARGETNAME

managed resource available only for freshly cleaned project

I created a SBT AutoPlugin that generates resources:
https://github.com/sphereio/json-schema-inliner/
(Thx to Why doesn't a custom resourceGenerator get executed upon compile?, I could fix my first problem.)
There is a test project that generates "test/inline/category.schema.json" for example.
The test project is in GIT as well: https://github.com/sphereio/json-schema-inliner/tree/master/testProject
This generated resource is available with a freshly cleaned project:
cd testProject
▶ sbt clean run
[...]
[info] Running Main
url from test/category.schema.json: file:/Users/yannsimon/projects/json-schema/testProject/target/scala-2.10/classes/test/category.schema.json
url from test/inline/category.schema.json: file:/Users/yannsimon/projects/json-schema/testProject/target/scala-2.10/classes/test/inline/category.schema.json
When running again, the managed resource disappears from "testProject/target/scala-2.10/classes/test/inline"
▶ sbt run
[...]
[info] Running Main
url from test/category.schema.json: file:/Users/yannsimon/projects/json-schema/testProject/target/scala-2.10/classes/test/category.schema.json
url from test/inline/category.schema.json: null
Any help would be appreciated.
Thanks, Yann
Answered in sbt issue: https://github.com/sbt/sbt/issues/2168#issuecomment-144133794
The fix was this is very simple: https://github.com/sphereio/json-schema-inliner/commit/eeb490189781e93c8c6eb15b504a158ce425b653

SBT Build Setup for Library and Multiple Command Line Tools

I'm trying to set up a Scala project, built using SBT, that will consist of a library and several command-line tools to do various things using that library. The library and tools are going to depend on another Scala project which I've installed into my local Ivy cache with sbt publish-local.
I've never used SBT before, so I'm a bit lost as to how to set this up. I would like several Linux executables or shell scripts in my top-level project directory, each of which executes a main() methods defined in a Scala file, and all of which depend on a single library. How do I get that sort of setup with an SBT project?
The way I'm thinking this will have to work is as an SBT configuration with multiple projects, and a bunch of wrapper shell scripts that execute sbt run in the appropriate project. However, when I run sbt run in my current single-project setup, I get, in addition to my program's intended output, a bunch of SBT noise:
Loading /pod/home/anovak/build/sbt/bin/sbt-launch-lib.bash
[info] Loading project definition from /pod/home/anovak/sequence-graphs/project
[info] Set current project to Sequence Graph API (in build file:/pod/home/anovak/sequence-graphs/)
[info] Running SequenceGraphs
Sequence Graphs are great!
[success] Total time: 2 s, completed Jan 6, 2014 6:01:17 PM
I would like my wrapper scripts to be able to run my command-line tools without seeing anything from SBT on screen at all. I think the [info] and [success] messages can be suppressed by messing about with the project's log level settings, but would that eliminate the "Loading..." line as well? If not, is there some other way to run an SBT project "on its own", without much/any interference from SBT?
I think what you need is one root project - sequence-graphs - with two submodules - library and cmd-tools.
project/build.properties would be as follows:
sbt.version=0.13.1
build.sbt for the root project would be as follows:
lazy val root = project in file(".") aggregate (library, `cmd-tools`)
lazy val library = project
lazy val `cmd-tools` = project dependsOn library
With only these two files you can run sbt and do projects to see the projects available.
[root]> projects
[info] In file:/Users/jacek/sandbox/so/sequence-graphs/
[info] cmd-tools
[info] library
[info] * root
At the same time SBT will create necessary subdirectories for the submodules.
With the project layout you start developing your own command-line tools in cmd-tools submodule.
To make things simple, I assume that a simple App-extending applications are enough.
cmd-tools/Hello1.scala
object Hello1 extends App {
println("Hello1")
}
cmd-tools/Hello2.scala
object Hello2 extends App {
println("Hello2")
}
With these two Hellos you can run cmd-tools/run from SBT shell in the root project.
[root]> cmd-tools/run
[info] Compiling 2 Scala sources to /Users/jacek/sandbox/so/sequence-graphs/cmd-tools/target/scala-2.10/classes...
Multiple main classes detected, select one to run:
[1] Hello2
[2] Hello1
Enter number:
The same could be run from the command line as sbt cmd-tools/run:
jacek:~/sandbox/so/sequence-graphs
$ sbt cmd-tools/run
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sequence-graphs/project
[info] Set current project to root (in build file:/Users/jacek/sandbox/so/sequence-graphs/)
Multiple main classes detected, select one to run:
[1] Hello1
[2] Hello2
Enter number: 1
[info] Running Hello1
Hello1
[success] Total time: 4 s, completed Jan 9, 2014 9:44:39 PM
Let's start it over as well as disable infos and [success]es messages.
jacek:~/sandbox/so/sequence-graphs
$ sbt --error 'set showSuccess := false' cmd-tools/run
Multiple main classes detected, select one to run:
[1] Hello1
[2] Hello2
Enter number: 1
Hello1
There's also the runMain command that Runs the main class selected by the first argument, passing the remaining arguments to the main method.
With that and the other examples you could have a sample command-line script to execute Hello1 as follows:
sbt --error 'set showSuccess := false' 'cmd-tools/runMain Hello1'
It could be even simpler when you use the sbt-onejar plugin that can Package your project using One-JAR™ With the plugin you don't have to use SBT after you distribute your command-line tools.
Quoting the plugin's documentation:
sbt-onejar is a simple-build-tool plugin for building a single executable JAR containing all your code and dependencies as nested JARs.
Please note that the Officially supported packages of SBT add some additional checks and printouts, i.e. tgz comes with bin/sbt script that does the following (amongst the other things):
echo "Loading $(dirname "$(realpath "$0")")/sbt-launch-lib.bash"
It's not an integral part of SBT itself, but the script itself that wants to do as much as possible so an end user is, say, happy. In your case, you are not necessarily happy, so either remove the line from the script or follow the steps as described in Manual Installation.

Resources