SBT - invalid system property 'sbt.repository.config' - scala

I am trying to build SBT project where I am pulling dependencies from internal repository. I followed this post to set repo.properties & stbconfig.txt. Here is the content of these files-
stbconfix.txt -
repo.properties-
After all above steps, SBT should have automatically pulled dependencies from internal repository but it isn't.
After that, I am trying to pass repo.properties path in command line but it is throwing error too-
No idea why it is complaining with invalid system property for 'sbt.repository.config'. Any help is very much appreciated.
Note- I tried upgrading SBT and installed it 2-3 times. I am currently on SBT 0.13.13.

Try adding the required property to SBT_OPTS environment variable before running sbt:
SET SBT_OPTS=-Dsbt.repository.config="your repo.properties path here"
sbt

Related

how can I change the coursier cache directory of the bundled sbt in IntelliJ

I've migrated my local coursier cache to another part of my system and changed the COURSIER_CACHE system property, as described in the coursier docs
My local installation of SBT works fine with this, via shell as well as via IntelliJ's sbt shell. However, when building my app using IntelliJ's build-in SBT using CTRL+F9, I get the following error:
scalac: Scala compiler JARs not found (module 'solipsism'): C:\Users\<user>\AppData\Local\Coursier\cache\v1\https\repo1.maven.org\maven2\org\scala-lang\scala-library\2.13.5\scala-library-2.13.5.jar, <etc>
with C:\Users\<user>\AppData\Local\Coursier\cache being the default coursier cache location.
So far, I tried to add the following VM Parameters to the Settings > Build Execution Deployment > sbt > VM Parameters without success:
-Dcoursier.cache=<repo dir>
-Dsbt.coursier.home=<repo dir>
as described in the SBT docs and in the coursier docs again
Verifying these settings via IntelliJ's SBT shell using csrCacheDirectory shows that they were picked up correctly, but the build error persists.
How can I change the coursier cache directory for the default build?
Using Windows 10, IntelliJ CE 2021.1.1, SBT 1.5.1
Thanks,
Cheers,
Joost Papendorp
Found the cause: IntelliJ had somehow retained the links to the old repository in the project structure. This is apparently not fixed by re-importing the project.
Solution: Delete entire Intellij project (not just the modules). Close IDE. Start new project. Re-import modules.
Classy.
https://get-coursier.io/docs/cache#sbtd mentions two options:
-Dsbt.coursier.home system property, or
COURSIER_CACHE environment variable

Why does sbt keep downloading my snapshot dependencies?

I have an SBT project that depends on two snapshot dependencies. Every time I build it, it goes off to the remote repository to fetch the dependencies. This is true even if I set offline := true.
When I look at how it is trying to resolve the local dependencies, the build is saying it is looking in "local", i.e., ~/.ivy2/local/... -- which is a nonexistent directory.
The jars are in ~/.ivy2/cache/... and this is where SBT downloads them when it pulls the dependencies from the remote server.
I have searched my .sbt and .scala build files and the string "local" does not appear in them in connection with a repository or cache.
SBT is at version 0.13.11 building against scala 2.11.8.
Why is SBT doing this, and how can I get it to see the cached jars?
If you want to prevent SBT from trying to download from official repositories you could simply create a file project/offline-repositories:
[repositories]
mirror-central: file:////nexus/central
mirror-maven-central-org: file:////nexus/maven-central-org
...
(/nexus/central and /nexus/maven-central-org should contain a (partial) mirror of what you need offline)
Then call sbt with the sbt.repository.config property configured:
-Dsbt.override.build.repos=true \
-Dsbt.repository.config=./project/offline-repositories
For Reference:
http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html
How to prevent SBT from trying to download from official repositories?
EDIT
If you want to use your ~/.m2 cache:
[repositories]
mirror-central: file:////home/XXXXX/.m2/repository
mirror-maven-central-org: file:////home/XXXXX/.m2/repository
...
This apparently is because in my Ivy cache I had a file named ~/.ivy2/cache/com.xxx/xxx-utils/ivy-2.3.2-SNAPSHOT.xml.original , which the build was trying and failing to parse. I'm not sure where this file came from; conceivably it was put there manually ages ago.

Why does sbt report "Error: Could not retrieve sbt 0.13.11"?

In a Scala project I updated the build.properties from 0.13.8 to 0.13.11. That "broke" sbt as it does not start anymore, i.e. it cannot download the 0.13.11 jars?! sbt prints a list of tried repo's, but the repo.typesafe.com was not one of them.
My local installed sbt is 0.13.8.
For some reason the scala-sbt jars are not available anymore in Typesafe's Bintray. Largest version there is 0.13.9.
I know the place to get it is https://repo.typesafe.com/typesafe/ivy-releases/, but how do I tell sbt to use this repo?
I have already tried:
adding a resolver to plugins.sbt
adding a resolver to build.sbt
adding the repo to .sbt/repositories
but I cannot get it working.
How to tell sbt where to get binaries?
Make sure that you're using sbt (launcher) that's at the same version of higher than the version used in your project.
Execute sbt about in an empty directory and find [info] This is sbt X.Y.X.
Make sure that you don't use ~/.sbt/repositories file that sets up the repositories used to resolve artifacts.
try to set your https proxy Information into http.proxyHost and http.proxyPort. This solved it for me.

In an sbt 0.13.7 project, compile the compiler-interfaces without compiling the project code

In a freshly checked out sbt ( 0.3.7 ) project and empty ivy cache, is it possible to trigger compilation of the compiler-interface(s) needed without compiling the project itself? I have poked around but haven't found a way.
Currently if a compiler-interface is required it will be created during compilation of the project. I would like to have this compiled directly in a separate command if possible. This would allow CircleCi to cache it saving 1-3 minutes with every build because it could be cached in the dependencies section of the circle.yml.
In sbt 0.13.12 compile:compileIncremental seems to do the trick. I ran inspect compile and inspected its dependencies to find the command.

Intellij unable to resolve references to a specific jar file

In a given project that is driven by sbt there is some kind of corruption in the project libraries specifically for a MavenLocal repository used for kafka-spark-9.7.2.jar in which:
references to the classes provided by that jar are marked as "symbol not found" by the editor parser
however the editor (strangely) does offer to import the classes
but after accepting the import, the symbols are still marked in red as unresolved.
The following attempts to "clean things up" have already been performed:
Build | Make Project
Build | Rebuild Project
In addition I have verified that the project does build from
sbt package
on the command line
UPDATE After re-running sbt gen-idea the librraries are still not found by the Parser. yet the libraries exist -even IJ knows about them as shown in the following screenshot. Why is it that IJ can find the library
C:\Users\S80035683\.ivy2\cache\org.apache.kafka\kafka\jars\kafka-0.7.2-spark.jar!\kafka\api\FetchRequest.class
However IJ is unable to resolve any classes from that library in the Parser?
You have to build the project for Intellij, try to do this in your project root:
sbt idea with-sources=yes
This should build the project structure from scratch and add the right dependencies, usually I refresh the project after adding a dependency or a jar.
Edit:
To use the command you need this plugin, otherwise you can use gen-idea but I used it only a few times and I'm not sure how it will work out.
Edit2:
There was some confusion, first, for the IDEA SBT console you don't need to prepend the sbt command since you already are inside sbt:
If you have the sbt plugin for idea you can use gen-idea with-source=yes (without prepending sbt)
From the terminal, either you go to your project root and type sbt to enter the sbt console and use gen-idea or idea with-sources=yes (without prepending sbt)
or directly sbt gen-idea or if you have the plugin sbt idea with-sources=yes (prepending sbt)
To reach the sbt console inside idea you need to install the sbt plugin on preferences -> plugin and search for sbt and then View -> Tool Windows -> SBT Console:
To start the console click on the play button, to kill the console on the skull.
I had the same problem. I fixed it by directly writing the CLASSES and SOURCES of the problematic library. This can be found in .idea/libraries/SBT__<problematic library>_jar.xml