How to include a library on bintray in Scala Maven project - scala

I'm making a project in Scala (2.11), using Maven as my build tool. I'd like to use this library, but I can't get it to work.
I have a minimal (2 files) example repository here: https://github.com/evertheylen/scala-maven-bintray-example
I added two dependencies, kafka and scala-kafka-client. Both times I followed the instructions on their respective websites, but the last one (from bintray) is giving me problems. I would like the repository to be defined in the project, and not in my personal settings.xml (though I did try that and it didn't work).
The error given to me by mvn package exec:java -Dexec.mainClass=be.evertheylen.SampleApplication is:
[ERROR] .../src/main/scala/SampleApplication.scala:3: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer
[ERROR] ^
[ERROR] .../src/main/scala/SampleApplication.scala:4: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer.Conf
[ERROR] ^
[ERROR] two errors found
Although mvn dependency:list does in fact list the library:
[INFO] The following files have been resolved:
...
[INFO] net.cakesolutions:scala-kafka-client_2.11:pom:0.10.0.0-RC2:compile
...

Try removing <type>pom</type> from the dependency declaration in your pom.xml.

Related

How to correctly prepare and setting preloaded sbt lib

In my situation, I cannot access internet in my office linux server. Therefore, I installed sbt in my personal computer. I followed instructions on sbt official web-site and run/compile a "hello world" for getting all dependency data.
Then, I copied ~/.ivy2 and ~/.sbt and sbt bin folders to my offline office desktop. But when I run sbt, I got these errors:
[info] welcome to sbt 1.4.9 (Oracle Corporation Java 1.8.0_25)
[info] loading project definition from /proj/mtk07847/test/scala/project
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scala-lang:scala-library:2.12.12
[error] Not found
[error] Not found
[error] download error: Caught java.net.SocketException: Connection reset (Connection reset) while downloading https://repo1.maven.org/maven2/org/s
cala-lang/scala-library/2.12.12/scala-library-2.12.12.pom
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
...
It seems that sbt tried to download missing scala-library:2.12.12 which I already prepared.
In my ~/.ivy2 folder,the structure and path looks like the following:
~/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.12.jar
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml.original
~/.ivy2/cache/org.scala-lang/scala-library/ivydata-2.12.12.properties
which is different from above messages:
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
should I modified any describing files to indicate searching path or rule for sbt? or this method
is totally wrong (if so, can anyone know the flow guide me the better way?)

object scalatest is not a member of package org [error] Cygwin

I was wondering if I could get some help with this one. I know there are many different issues with the same title, however, after following all the instructions (I hope), I could not get it to compile still. I've been at this for over 7 hours.
This is my issue. I am using Cygwin64 terminal to do some scala programming with sbt. I run the test and make sure that the test file is in the test folder but nothing is working. I have tried to compile it without the test file and then bring it back in but it does not work either.
$ sbt test
[info] Loading project definition from C:\cygwin64\home\Sam\hof\project
[info] Set current project to hof (in build file:/C:/cygwin64/home/Sam/hof/)
[info] Compiling 1 Scala source to C:\cygwin64\home\Sam\hof\target\scala-2.10\test-classes...
[error] C:\cygwin64\home\Sam\hof\src\test\scala\TestSuite.scala:3: object scalatest is not a member of package org
[error] class TestSuite extends org.scalatest.FunSuite {
[error] ^
[error] C:\cygwin64\home\Sam\hof\src\test\scala\TestSuite.scala:5: not found: value test
[error] test("map2 with add"){
[error] ^
[error] two errors found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Sep 19, 2016 1:07:10 AM
Is there anything I can do?
I had the same problem. Running sbt test in the project root gave me the object scalatest is not a member of package org error. But when I changed to src/test directory, it completed successfully.

Scalc SBT compile failing

I am trying to follow code from below link
http://spark.apache.org/docs/latest/quick-start.html
But when I am trying to create package it is failing. I want to know 2 thinks
obviously, why it is failing
why it is showing older version of the scala, while I mentioned 2.11
Below is the error message.
[info] Set current project to default-0464ce (in build file:/home/ubuntu/simple_sbt/)
[info] Updating {file:/home/ubuntu/simple_sbt/}default-0464ce...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/ubuntu/simple_sbt/target/scala-2.9.1/classes...
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:1: object apache is not a member of package org
[error] import org.apache.spark.SparkContext
[error] ^
[error] /home/ubuntu/simple_sbt/src/main/scala/SimpleApp.scala:2: object apache is not a member of package org
[error] import org.apache.spark.SparkContext._
[error] ^
[error] two errors found
[error] {file:/home/ubuntu/simple_sbt/}default-0464ce/compile:compile: Compilation failed
[error] Total time: 2 s, completed Aug 30, 2016 3:19:18 AM
when you run sbt package , sometimes it fails as there are no dependencies that are downloaded and will be resolved for the files imported.
Try running, sbt run first and then sbt package . sbt run should bring in all the dependencies on top of which packaging and compiling will be possible.
If the above does not solves your problem, you need to share your sbt build file and the environment that you are using. In which directory you are running these commands, will also play a role.

Adding #RunWith for jbehave-junit-runner breaks JBehave build using Maven

I'm using JBehave with my Maven build which I also develop in Eclipse and sometimes run the my unit tests with the JUnit runner in Eclipse. I found jbehave-junit-runner works well for beautifying the JBehave stories in the JUnit runner. However, adding jbehave-junit-runner seems to have broken my Maven build.
Result of mvn clean install after installing https://github.com/codecentric/jbehave-junit-runner:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
/Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
/Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[50,28] error: cannot access Runner
[INFO] 5 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.043 s
[INFO] Finished at: 2014-12-23T15:38:39-08:00
[INFO] Final Memory: 14M/156M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project followerdownloader-frontend: Compilation failure: Compilation failure:
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[50,28] error: cannot access Runner
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
What is it about https://github.com/codecentric/jbehave-junit-runner that broke my build?
The solution to the problem is to broaden the scope of junit by removing the test element from the junit in the pom.xml file:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<!-- <scope>test</scope> --> <!-- SOLUTION: COMMENTED OUT THIS LINE -->
</dependency>
I think I stumbled into a paradox of JBehave and Behavior Driven Design (BDD):
On the one hand, BDD is not testing (see http://jbehave.org/reference/stable/examples-philosophy.html).
On the other hand, a tool for BDD, https://github.com/codecentric/jbehave-junit-runner, depends on the #RunWith annotation that's in a test framework, specifically org.junit.runner.RunWith.
I worry that my solution may have consequences for my production code if I'm no longer limiting the scope of junit to the Maven standard test directory.
Nevertheless, my solution did solve the original problem.

Is it possible to reference a project with a different SBT version?

I have my project (just for experiments with sbt) which is based on sbt 0.10. And another one which I want to use as a dependency. It is sbt 0.7 based.
Currently I'm trying to include the second it into my project project using uri reference. But the build is failing, probably because of incompatible versions of sbt in these projects. The error message is:
[info] Compiling 1 Scala source to /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/target/scala-2.8.1.final/classes...
[error] /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/Plugins.scala:1: not found: value sbt
[error] import sbt._
[error] ^
[error] /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/Plugins.scala:3: too many arguments for constructor Object: ()java.lang.Object
[error] class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
[error] ^
... and so on.
Can I somehow reference the second project so it will be possible to bild and/or run my project with just one command?
SBT cross-project references are only supported if both projects use SBT 0.10. But you can use publish and artifact and depend on this from the downstream project through Ivy.
Issue the publish-local command in the first project to package the code in a JAR and write it to ~/.ivy2/local/org.abc.def/....
In the SBT 0.10 project, add this setting:
libraryDependencies += "org.abc" %% "def" % "0.1"