what does pomOnly() do in .sbt files? - scala

what does pomOnly() do in .sbt files?
For example,
"com.github.fommil.netlib" % "all" % "1.0" pomOnly()

Indeed, SBT reference guide does not seem to provide much info about pomOnly().
As per mvnrepository, the dependency "com.github.fommil.netlib:all" corresponds to an aggregate pom.xml:
<dependency>
<groupId>com.github.fommil.netlib</groupId>
<artifactId>all</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
The call of pomOnly() in build.sbt indicates to the dependency management handlers that they should not look for jar libs/artifacts for this dependency, but only load the metadata from the aggregate pom.

Related

Scala async import not working on IntelliJ

value async is not a member of scala
import scala.async.Async.{async, await}
Can you import anything from the scala.async package at all ?
The scala.async package is not automatically imported in Scala.
To use it, you need to add it as a dependency to your project.
This depends on the build tool you use for your project.
If you use sbt, you need to add this dependency to your build.sbt:
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "1.0.1"
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
For maven, you should add this in your pom.xml:
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-async_2.13</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>2.13.8</version>
<scope>provided</scope>
</dependency>
You might need to check your Scala version, as per the official documentation:
As of scala-async 1.0, Scala 2.12.12+ or 2.13.3+ are required.
Also, be sure to check if you need to to enable compiler support for async.
You will find everything I provided in more detail at their official documentation. You should also check their github to see the latest release.

Scala SBT - External repository

I try to use the sbt from Scala. But i need reference to an external repository.
This is the pom.xml from https://www.spigotmc.org/wiki/spigot-maven/
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--This adds the Bukkit API artifact to the build -->
<!-- Do not include this in the pom.xml file if the Spigot API is already added -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Actually, i have this :
name := "MyProject"
version := "1.0"
scalaVersion := "2.13.1"
libraryDependencies ++= Seq(
"org.spigotmc" % "spigot-api" % "1.15.1-R0.1-SNAPSHOT" % "provided",
"org.bukkit" % "bukkit" % "1.15.1-R0.1-SNAPSHOT" % "provided"
)
But i have an error saying that the dependence is not found
[error] not found: https://repo1.maven.org/maven2/org/spigotmc/spigot-api/1.15.1-R0.1-SNAPSHOT/spigot-api-1.15.1-R0.1-SNAPSHOT.pom
[error] https://hub.spigotmc.org/nexus/content/repositories/snapshots/ doesn't point to a file
I don't know (also with the doc https://www.scala-sbt.org/1.x/docs/) how to refer to https://hub.spigotmc.org/nexus/content/repositories/snapshots/
Can you help me please ?
Thanks ^^
Since the artifact is not present in default mvn repository (https://repo1.maven.org/maven2/), you need to add the spigot repo.
resolvers+="Spigot Snapshots" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
So the build.sbt will look like
name := "MyProject"
version := "1.0"
scalaVersion := "2.13.1"
resolvers+="Spigot Snapshots" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
libraryDependencies ++= Seq(
"org.spigotmc" % "spigot-api" % "1.15.1-R0.1-SNAPSHOT" % "provided",
"org.bukkit" % "bukkit" % "1.15.1-R0.1-SNAPSHOT" % "provided"
)
You can follow the reference manual at https://www.scala-sbt.org/1.x/docs/Resolvers.html
I was able to resolve the dependency by building spigot locally with BuildTools.jar and adding Maven local as a resolver.
resolvers += Resolver.mavenLocal,
libraryDependencies += "org.spigotmc" % "spigot-api" % "1.16.4-R0.1-SNAPSHOT" % "provided"

Porting Axis2 project to sbt / scala: how to deal with .mar files?

I am porting a Java / Maven app over to sbt / scala and I've had some issues with an Axis2 dependency, namely the need to pull the "addressing.mar" artifact into the project. SBT chokes on this, and also I'd like the idea plugin to create the file.
Currently the build gives and error but I was able to put the file into a local lib folder and pull it into the project that way.
More info about MAR here: http://ssagara.blogspot.com/2009/03/axis2-maven-module-mar-plug-in.html
I'd like to use:
libraryDependencies += "org.apache.axis2" % "addressing" % "1.5.6"
This does not work; the equivalent mvn dep would be:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>addressing</artifactId>
<version>1.5.6</version>
<type>mar</type>
</dependency>
I was hoping I could append something to the end of the dependency ala:
libraryDependencies += "org.apache.axis2" % "addressing" % "1.5.6" % withType("mar")
But I haven't found a way to do this.
SBT: 0.12.2
The artifact is properly resolved, which you can see with show update or by looking at the resolution report in target/resolution-cache/reports/. It is not included on the classpath by default, however. The types of artifacts included on the managedClasspath are controlled by classpathTypes. To include mar, set:
classpathTypes += "mar"

Test jar dependency in Play?

I have a maven module which has some common code for integration tests in test sources directory. I build a test-jar containing these classes.
in Maven I would use following (as said in http://maven.apache.org/guides/mini/guide-attached-tests.html):
<dependency>
<groupId>com.myco.app</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type> <!-- this is the important part-->
<scope>test</scope>
</dependency>
in order to use this in another module.
How do I define such dependency on test-jar in Play (or SBT)?
You have to use the "tests" classifier, as explained in this doc:
"com.myco.app" % "foo" % "1.0-SNAPSHOT" % "test" classifier "tests"

How to exclude commons-logging from a scala/sbt/slf4j project?

My scala/sbt project uses grizzled-slf4j and logback. A third-party dependency uses Apache Commons Logging.
With Java/Maven, I would use jcl-over-slf4j and logback-classic so that I can use logback as the unified logging backend.
I would also eliminate the commons-logging dependency that the third-party lib would let sbt pull in. I do the following in Maven (which is recommended by http://www.slf4j.org/faq.html#excludingJCL):
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
And the question is, how to do the same with sbt?
Heiko's approach will probably work, but will lead to none of the dependencies of the 3rd party lib to be downloaded. If you only want to exclude a specific one use exclude.
libraryDependencies += "foo" % "bar" % "0.7.0" exclude("org.baz", "bam")
or
... excludeAll( ExclusionRule(organization = "org.baz") ) // does not work with generated poms!
For sbt 0.13.8 and above, you can also try the project-level dependency exclusion:
excludeDependencies += "commons-logging" % "commons-logging"
I met the same problem before. Solved it by adding dependency like
libraryDependencies += "foo" % "bar" % "0.7.0" exclude("commons-logging","commons-logging")
or
libraryDependencies += "foo" % "bar" % "0.7.0" excludeAll(ExclusionRule(organization = "commons-logging"))
Add intransitive your 3rd party library dependency, e.g.
libraryDependencies += "foo" %% "bar" % "1.2.3" intransitive