Truststore setup for sbt plugin in IntelliJ - scala

We are using IntelliJ (CE 2018.3) with sbt 1.2.3 and Artifactory. Since our Artifactory is protected by a self-issued certificate, we would like to add -Djavax.net.ssl.trustStore=c:/my/custom/cacerts to the sbt command line as it is invoked in IntelliJ (or even better: anytime we invoke sbt on our PCs).
We would like to avoid patching the truststore of our JVM, since it's distributed to our machines through channels we do not control.
Are there any globally available environment flags or sbt settings that we can use for that, something like the sbt global settings?
Tried to specify all these flags in the IntelliJ sbt settings (which seems to be the proper place to do it), but it got stuck forever in "Refreshing project"
File > Settings > Build, Execution, Development > sbt > VM Parameters
-Dsbt.override.build.repos=true -Dsbt.repository.config=./some/path/sbt.repositories -Dsbt.boot.credentials=%USERPROFILE%/.sbt/.credentials -Djavax.net.ssl.trustStore=c:/Users/%USERNAME%/mycacerts
The command-line build works, using the flags shown above.

It works, as long as I don't try to use parameter substitution, i.e.
-Dsbt.boot.credentials=%USERPROFILE%/.sbt/.credentials does not work, but
-Dsbt.boot.credentials=C:/Users/MyUser/.sbt/.credentials works.

Related

SBT Console in Intellij

I am beginner in Scala. I cant find how to add SBT Console.
I have sbt shell, but in Scala course i see that they have both: SBT Shell and SBT Console, and using the second one. I tried to write "console" in sbt shell, and after "run", but it says:
error: not found: value run.
So I just want to add somehow this SBT Console, to run my program not only from button "run" in Intellij.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
You're probably confused by "Shell" and "Console" usually being synonyms, but they actually mean different things with sbt.
sbt shell - is, uhm, a shell that sbt gives you when you run it in interactive mode - i.e. when you just run sbt from your terminal. This gives you access to other exciting things, such as running the app (with run command), inspecting the build (inspect ...), running tests (test, obviously) and so on.
sbt console - is an interactive REPL (read-evaluate-perform-loop) that gives you scala as an interpreter - i.e. you can type in (or paste) some scala code, and it will be immediately compiled and evaluated - outputting the results. Sbt console is also available from sbt shell - by running console.
So, in order to run your program, you have two options (besides the IntelliJ "run" dialog):
From your terminal do sbt run
From your terminal do sbt, then wait for sbt to initialize, then in the sbt shell do just run.
Refer to sbt docs for more details on different ways to run sbt (spoiler: there's also "batch" mode, where you can run sbt run from your terminal - and it is exactly the same as sbt and then run).
Sbt Reference manual might also be helpful - specifically it covers the sbt console command.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
It is not mandatory - you can run scala with maven, it's just a bit more involved to configure. However, if you allow a bit of personal opinion, I'd recommend using sbt with scala projects (and even with Java projects). For one simple reason - the build definition in sbt is essentially just scala code - you can use any language features, third part libraries and even custom code in your build - which sometimes comes very helpful. Compared to maven, I think it's a big step forward, as in maven you define the build using a XML-based "language" defined by the mvn tool and it's plugins - which is much less customizable.
However, gradle also has this advantage, so pick the tool that best suits your needs.

How to log commands issued from Intellij with Scala plugin to SBT

I worked some time with SBT and a text editor. Then, moved to Intellij, installed Scala plugin, and created a new project as in the picture here by choosing it to be based on SBT. Also, in the settings, I chose the SBT launcher to be custom, and made it point to the already-installed sbt.
I believe Intellij is probably calling SBT commands like sbt run and stuff in the background. My question: How can I see (a log of) these commands as they're called by Intellij to sbt and their responses? And as a plus: where can I edit them? I opened the "Edit Configurations" but couldn't find anything like sbt compile.
I believe Intellij shows the responses (e.g., [info] downloading...) below in the "Background Tasks", but
1. It doesn't log these responses and
2. It doesn't show the commands issued by Intellij to sbt.
Big picture/what I'd really want to do: have the IntelliSense features from Intellij and Scala plugin, but build and run from the terminal and not have any effects from Intellij on that.
The IntelliJ Scala plugin doesn't (yet) call sbt except for project import/refresh or if you have a run configuration that uses sbt. Compilation is done by the built-in compile server. If you prefer to use IntelliJ as an editor and run tasks from the sbt console, that usually works fine.
I don't understand the question well
do u want to see the SBT output? if you are using run/debug you will see both the command & the output in the run window (alt+4)
also intelliJ has a window called event log
I hope that help
Intellij reads the projects configuration from sbt and creates an equivalent configurations for its project format (either .idea folder or .ipr)
this is a similar question to yours but about maven, you may find helpful:
https://stackoverflow.com/a/30167052/2675679

How does sbt determine that it needs to update

I've tried to run application inside firejail without network. When I run sbt in host system, all goes ok, sbt finds all libraries. Then I try to run sbt inside restricted environment with read-write access to ~/.sbt, ~/.ivy2, ~/.m2 and project folders and read-only access to .sbt binary. Sbt loses all dependent libraries and try go get them from network, which is disabled.
Where do sbt store library cache and why do it refuse to take old compiled and ready to use state?
update: sbt fails on the time it tries to build global plugins. It does not get to the stage where it performs project build. I've tried to add offline := true both to the project and global sbt configuration, but sbt tries to update plugins nevertheless.
update2: I've managed to run sbt successfully without rebuilding all global plugins. That requires access to /etc. But I would prefer not to give access to /etc. What information do SBT need from /etc? Hostname or something else? Why on earth it make cache depend on such things?
update3:
I've discovered the exact cause for SBT failing to recognize already downloaded libraries. /etc/passwd is strictly needed for SBT to work correctly. Could anyone point in what way SBT uses login info exactly?

Eclipse run mvn with command parameter (e.g. --encrypt-master-password)

I never had to do this before but maybe someone else has.
I want to run "mvn --encrypt-master-password".
I'm on a machine with only Eclipse and m2e. I could of course download and set up maven on my hard drive with the appropriate JAVA_HOME envvars etc, but I figured I'd try to get it done quickly in Eclipse.
m2e quickly gives a "no goals have been specified" error.
I could put in a dummy goal but I can't see any way to enter a mvn command line parameter (as opposed to a 'goal parameter')
This is theoretical now since I'll go and do this on a command line somewhere, but I'd like to know if it's possible.
For a one-time password encryption job you can set --encrypt-master-password <your password> as a goal in the Maven build as already specified by flafoux (Run Configurations > Maven Build > New build > ...).
But this is not secure since you password is stored in a configuration (unless you delete it right after the execution). And this is also not handy since you need to update a job manually for every encrypted password you need...
ps: https://maven.apache.org/guides/mini/guide-encryption.html says since 3.2.1 Maven should ask for the password if not specified, but it does not at least at my eclipse lune having Maven 3.2.1 embedded - may be it does at more recent verions.
You can set goals with build configuration.
Create a maven build configuration (Run as > Run Configuration... Maven builds , and add goals.
more explanation : http://books.sonatype.com/m2eclipse-book/reference/running-sect-running-maven-builds.html

How to use existing Intellij projects as a I move forward with SBT?

Novice SBT question - Now that I've started with some basic SBT tutorials, I'd like to start using SBT build files (within Intellij) a lot more often. However, there's a couple of problems with this :
1) Existing projects that I currently publish to a jar, and later import into other projects... how do I publish this jar file to my local repository? SBT publish-local doesn't seem to fit my situation, because the project was made in Intellij and is not (yet) an SBT project.
2) Suppose I do convert the project to an SBT build setup (and then import it into Intellij).. how do I configure Intellij to to publish-local (update) each time I build the project? I do not see many configurable settings around SBT within the new Intellij SBT support.
Using Intellij 13 and SBT 0.13.1
Thanks!
to get you started up quickly on using SBT to drive Idea, have a look at my template project called skeleton
It supports most of the basic tasks you'd want to do.
To publish to your repository, use the publish task.
hope that helps!
For publishing, you simply use the publish action:
To specify the repository, assign a repository to publishTo and optionally set the publishing style. For example, to upload to Nexus:
publishTo := Some("Sonatype Snapshots Nexus" at "https://oss.sonatype.org/content/repositories/snapshots")
As for your second question, despite being a JetBrains fanboy, I have found SBT integration quite disappointing. For one thing, as the JetBrains documentation states itself, you need two plugins: their plugin and sbt-idea. You use sbt-idea to synchronize the IDEA module structure with the SBT build, and you use JetBrains' idea-sbt-plugin to execute SBT tasks in the "Before Launch" action in Run Configurations.
It sounds like you want to do an "install" on every build, so "Before Launch" action support isn't useful. I would suggest writing your own custom SBT task to install on build and using the Command Line Tools Console to execute that task with SBT as if from the command line. I know; that indirection is annoying.
Bear in mind one more thing. I have found numerous bugs with idea-sbt-plugin. At least on Mac. JetBrains told me the next version will be much better, and you can see for yourself with the next EAP version.
I certainly welcome others who have managed to have more success than I have to chime in.