Environment Variables are not read by Intellij from ~/.bash_profile (Mac OS) - scala

I defined some Environment Variables in ~/.bash_profile,like
export MVN_REPOSITORY_USERNAME=myself
export MVN_REPOSITORY_PASSWORD=myselfPwd
In my SBT plugin configuration project/plugin.sbt I use:
sys.env.get("MVN_REPOSITORY_USERNAME")
If I load my SBT-Project with IntelliJ, they are not set.
However if I start the SBT-Console of IntelliJ, they are set.
Is there any special configuration needed in IntelliJ?

You need to make sure that you source ~/.bash_profile. This is a silly mistake, but an all too common one.

Actually with this SBT Setting it works:
intellij-sbt-settings.png

Related

Truststore setup for sbt plugin in IntelliJ

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.

How to make -Dsbt.override.build.repos=true global for SBT?

I want to override all repos even the ones introduced inadvertently in my build.sbt files so we can point to our proxy and have a common binary base for all the team. The option
$ sbt -Dsbt.override.build.repos=true
does the job but I'd like to make this option permanent. I've been looking at http://www.scala-sbt.org/release/docs/Global-Settings.html but I don't know how to translate that option to the global.sbt file they mention.
How would you configure that option globally?
Add -Dsbt.override.build.repos=true to the SBT_OPTS environment variable
When running on windows, it can be defined in the file sbtconfig.txt under <SBT_HOME>/bin :
-Dsbt.override.build.repos=true
You can create this file if you don't have it already

Why does IDEA report errors for build.sbt in a new sbt project?

I'm running IntelliJ 13.1.5 community edition. I've got JDK, Scala, SBT installed. The JAVA_HOME, JDK_HOME, SCALA_HOME and SBT_HOME variables are set. If I create a new SBT project, after initial sbt refresh, I get this:
The thing compiles and runs fine, even if I add dependencies, but the file itself shows tonnes of errors. F4 settings show empty SBT module stuff:
I then installed https://github.com/mpeltonen/sbt-idea and ran sbt gen-idea in the project folder. This created a bunch of files, and reloading the project, the reds in the sbt file went away.
This is on my laptop. However, on my work machine, simply creating a new project works fine, and the sbt file isn't filled with red. Can't seem to figure out how that machine's different. Any pointers on how to resolve this annoying issue?
In case IntelliJ IDEA struggles a bit with caching, try the first and if still not working the second should definitely do the trick:
File -> Invalidate cache and restart
Close IDEA, delete .idea, re-import your project
I was also getting highlighted errors in all of the build.sbt file.
What fixed it was to select to Download "Sources for SBT and plugins" in the Import Project from SBT window.
Please, check if you added the “scala-library*.jar” to Scala compiler library
This link might be helpful:
http://blog.jetbrains.com/scala/2010/09/02/project-configuration-explained/
If you are using windows or linux, please also see:
http://confluence.jetbrains.com/display/SCA/Setting+up+Scala+plugin+project+in+IntelliJ+IDEA
Update on 2020, Apr
This works for scala 2.13 and Intellij 2020.1 when:
sbt files has error
project structure is wrong
Reason is 'External libraries' from sbt is not loading for IDE.
To do so, similar to old version: https://www.lagomframework.com/documentation/1.6.x/java/IntellijSbtJava.html
1. rm -rf .ida
2. Click Menu item: Open... to pick the project directory
If not working, I assume you need to setup Global SDK for intellij by
cmd+; and pick the path of scala.
In case of mac,
brew install scala normally echo out the path /usr/local/opt/scala/idea
Let ide browse to this path by holding cmd+shift+G to open path.
IDE should find the path like /usr/local/Cellar/scala/2.13.1/idea/lib/scala-library.jar and scala-compiler.jar and scala-reflect.jar
There might be better way to do the global scala setting though.

Setting environment variables in eclipse that references other environment variables

I have Eclipse Helios with a java program set up. I'm attempting to create two environment variables
ReportingManagerHome=C:\rp
ReportingManagerConfig=${ReportingManagerHome}\config
I then run my program with
System.out.println(System.getenv("ReportingManagerConfig"));
Eclipse doesn't even call the java compiler. It throws up a pop up window with the error that environment variable ReportingManagerHome is not defined. I understand that since the java compiler has yet to be called, technically Eclipse is correct.
Now how do I work around this so that I can define cascading environment variables in Eclipse?
It won't recursively expand environment variables from the launch config.
Even using ${env:VAR} takes it from the environment variables from your eclipse process, not from your current launch config.
The most reliable way to do it is to go to Preferences>Run/Debug>String Substitution and define an eclipse variable there.
Then define the environment variables in your launch config:
ReportingManagerHome=${RMH}
ReportingManagerConfig=${RMH}\config
In Eclipse Mars and later you can use
${env_var:VAR_NAME}

Scala plugin for netbeans

I try to run scala plugin under NetBesans 6.9.1. I install scala from arch linux repositories. Then i download netbeans-6.9.1 and scala plugin. Installed plugin. When i create scala application with hello world and try it to build i get error:
You must set SCALA_HOME or environment property and append "-J-Dscala.home=scalahomepath"
property to the end of "netbeans_default_options" in NetBeansInstallationPath/etc/netbeans.conf to point to
Scala installation directory.
How can i fix it?
I put in my netbeans.conf J-Dscala.home=/usr/bin/scala but it's not helpful. After that i get error: Could not load definitions from resource scala/tools/ant/antlib.xml. It could not be found.
Thank you.
If you don't want to mess up with the environment variables in linux while setting up scala in netbeans then:
search for "scala-library.jar"
wherever you find it, copy that location and assign "J-Dscala.home" to that
for example
"J-Dscala.home=/home/username/project/.../scala2.8.1"
that's it.
It worked out for me
try it in your case.
I do not have Arch Linux installed, but looking at scala package contents I think the proper value for SCALA_HOME is /usr/share/scala.
Isn't the error message helpful enough? Did you edit the netbeans.conf file?