How to enable play-querydsl plugin in Play 2.2? - playframework-2.2

I have problem setting up querydsl framework in play 2.2.6 with scala 2.10.3 and java 1.7
I have done installation exactly like it was in documentation. But it doesn't work.
I am gettign an error:
dany#dany1L:~/git/app$ playFramework-2.2.6
[info] Loading project definition from /home/dany/git/app/project
/home/dany/git/app/build.sbt:11: error: not found: value QueryDSLPlugin
val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)
^
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Here is my project/plugins.sbt:
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
// changed to support play 2.2.4 addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.6")
addSbtPlugin("com.code-troopers.play" % "play-querydsl" % "0.1.2")
And my build.sbt:
import com.typesafe.config._
import play.Project._
import sbt._
import Keys._
//javacOptions ++= Seq("-Xlint:unchecked")
playJavaSettings
playJavaSettings ++ QueryDSLPlugin.queryDSLSettings
val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)
val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
name := conf.getString("app.name")
version := conf.getString("app.version")+"_("+conf.getString("app.releaseDate")+")"
libraryDependencies ++= Seq(
javaJdbc,
javaJpa,
"org.hibernate" % "hibernate-entitymanager" % "3.6.9.Final",
"mysql" % "mysql-connector-java" % "5.1.27",
"org.mindrot" % "jbcrypt" % "0.3m",
"org.jasypt" % "jasypt" % "1.9.2",
"org.apache.poi" % "poi" % "3.10.1",
"com.googlecode.genericdao" % "dao" % "1.2.0",
"com.googlecode.genericdao" % "search-jpa-hibernate" % "1.2.0",
"com.google.code.gson" % "gson" % "2.3.1",
"com.googlecode.json-simple" % "json-simple" % "1.1.1",
"javax.mail" % "javax.mail-api" % "1.5.3",
"javax.activation" % "activation" % "1.1.1",
"com.sun.mail" % "javax.mail" % "1.5.3",
"com.querydsl" % "querydsl-jpa" % "4.0.2",
"com.querydsl" % "querydsl-apt" % "4.0.2",
cache
)
Please give me some help.
After adding:
import codetroopers._
on top of build.sbt I am getting an error:
[info] Loading project definition from /home/dany/git/app/project
error: bad symbolic reference. A signature in QueryDSLPlugin.class refers to type AutoPlugin
in package sbt which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling QueryDSLPlugin.class.
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

Thanks to #Nathan
and his answer here
Finally after few days of struggle I've make it working.
Here are my configuration files:
plugins.sbt
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
// changed to support play 2.2.4 addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.6")
addSbtPlugin("com.code-troopers.play" % "play-querydsl" % "0.1.1")
and build.sbt
import com.typesafe.config._
import play.Project._
import sbt._
import Keys._
//javacOptions ++= Seq("-Xlint:unchecked")
playJavaSettings
val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
name := conf.getString("app.name")
version := conf.getString("app.version")+"_("+conf.getString("app.releaseDate")+")"
libraryDependencies ++= Seq(
javaJdbc,
javaJpa,
"org.hibernate" % "hibernate-entitymanager" % "3.6.9.Final",
"mysql" % "mysql-connector-java" % "5.1.27",
"org.mindrot" % "jbcrypt" % "0.3m",
"org.jasypt" % "jasypt" % "1.9.2",
"org.apache.poi" % "poi" % "3.10.1",
"com.googlecode.genericdao" % "dao" % "1.2.0",
"com.googlecode.genericdao" % "search-jpa-hibernate" % "1.2.0",
"com.google.code.gson" % "gson" % "2.3.1",
"com.googlecode.json-simple" % "json-simple" % "1.1.1",
"javax.mail" % "javax.mail-api" % "1.5.3",
"javax.activation" % "activation" % "1.1.1",
"com.sun.mail" % "javax.mail" % "1.5.3",
"com.querydsl" % "querydsl-jpa" % "4.0.2",
"com.querydsl" % "querydsl-apt" % "4.0.2",
cache
)
playJavaSettings ++ QueryDSLPlugin.queryDSLSettings
val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)
QueryDSLPlugin.queryDSLPackage := "models"
and build.properties
sbt.version=0.13.0

Related

Why does compiling Holden Karau's spark-testing-base generate an error?

I am trying to use Holden Karau's spark-testing-base using sbt and get 4 errors. It looks like sbt is generating invalid references to 4 jars.
The errors are:
[error] 4 not found
[error] https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common/2.6.0/hadoop-common-2.6.0.test-jar
[error] https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-hdfs/2.6.0/hadoop-hdfs-2.6.0.test-jar
[error] https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-mapreduce-client-jobclient/2.6.0/hadoop-mapreduce-client-jobclient-2.6.0.test-jar
[error] https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-yarn-server-tests/2.6.0/hadoop-yarn-server-tests-2.6.0.test-jar
My build.sbt contains:
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.2.1",
"org.scalacheck" %% "scalacheck" % "1.12.4",
"com.holdenkarau" %% "spark-testing-base" % "1.6.1_0.3.3"
)
parallelExecution in Test := false
lazy val root = (project in file(".")).
settings(
name := "core",
version := "1.0",
scalaVersion := "2.11.8"
)
And my test class is from Holden's wiki example:
import org.scalatest._
import com.holdenkarou.SharedSparkContext
class SampleTest extends FunSuite with SharedSparkContext {
test("test initializing spark context") {
val list = List(1, 2, 3, 4)
val rdd = sc.parallelize(list)
assert(rdd.count === list.length)
}
}
When I execute sbt test I get a bunch of maven updates followed by the errors listed above.
It appears that sbt is generating invalid jar names - for example https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common/2.6.0/hadoop-common-2.6.0.test-jar should be hadoop-common-2.6.0-test.jar (i.e. the separator after the 2.6.0 should be -, not .).
Can someone guide me as to why this is occurring, and how to fix it?

sbt and play test with #RunWith

I'm dealing with a problem working on a Play project and sbt.
The problem is:
I have tests, some of them are using PowerMockito, some of them aren't
For the tests using PowerMockito, I've added #RunWith(PowerMockRunner.class) at the beginning of the class.
For the tests not using, I've added nothing.
Here is an example for a test that uses PowerMockito
#RunWith(PowerMockRunner.class)
#PrepareForTest({SomeMockedClass.class})
public class SomeClassTest {
#Test
public void aTest() {
PowerMockito
.stub(PowerMockito.method(SomeMockedClass.class, "aMethod"))
.toReturn(something);
assertThat(someCall).isEqualTo(something);
}
}
Here is an example for a test that doesn't use PowerMockito
public class AnotherClassTest {
#Test
public void anotherTest(){
assertThat(something).isEqualTo(something);
}
}
And here is my build.sbt dep:
libraryDependencies ++= Seq(
cache,
...
// Testing
"org.easytesting" % "fest-assert" % "1.4" % "test",
"junit" % "junit" % "4.12" % "test",
"org.powermock" % "powermock-mockito-release-full" % "1.6.2" % "test",
"org.powermock" % "powermock-module-junit4-rule-agent" % "1.6.2" % "test",
"org.easymock" % "easymock" % "3.3.1" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test"
)
Here is the problem:
When I run my tests from IntelliJ, it founds all tests and everything is ok
When I run my tests from activator (activator test), it does NOT found the tests with the #RunWith.
I've read some post about it, like the sbt version or something
(even https://github.com/sbt/jacoco4sbt/issues/15).
But the sbt version is : 0.13.8-M5 so it seems ok.
Play version is : 2.3.8
If you guys have any clue that'd be great.
Thanks

sbt - migrating IntelliJ Play application to 2.3.x

I am starting to work with IntelliJ/Scala/Play I created a new Play2 application and it works just fine. I have been trying to migrate it from Play 2.2.1 to 2.3.5 but I am getting an error
can not resolve symbol enablePlugins
My files look like
build.properties:
sbt.version=0.13.5
plugins.sbt:
logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.0")
// web plugins
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.0.0")
build.sbt:
import play.Project._
name := "Play2App"
version := "1.0"
//playScalaSettings
lazy val root = (project in file(".")).enablePlugins(PlayJava SbtWeb)
Thanks for any help
You miss a comma between "PlayJava" and "SbtWeb"
lazy val root = (project in file(".")).enablePlugins(PlayJava,SbtWeb)

Play 2.3 subproject dependsOn

This is how I configure the subprojects at Play 2.3. However, it gives me sbt.ResolveException: unresolved dependency. What is wrong with my settings? This works in 2.2.
val model = Project(appName + "-model", file("models")).enablePlugins(play.PlayScala).settings(
version := appVersion,
libraryDependencies ++= modelDependencies
)
val main = Project(appName, file(".")).enablePlugins(play.PlayScala).enablePlugins(SbtWeb).settings(
version := appVersion,
libraryDependencies ++= appDependencies
).dependsOn(model % "test->test;compile->compile")
try this:
lazy val model = Project(
id = s"${appName}-model",
base = file("models"))
.enablePlugins(play.PlayScala)
.settings(version := appVersion)
.settings(scalaVersion := "2.11.1" )
.settings(libraryDependencies ++= modelDependencies)
lazy val main = Project(
id = appName,
base = file("webapp"))
.enablePlugins(play.PlayScala)
.enablePlugins(SbtWeb)
.settings(name := "play-scala")
.settings(version := appVersion)
.settings(scalaVersion := "2.11.1" )
.settings(libraryDependencies ++= appDependencies)
.dependsOn(model % "test->test;compile->compile")
override def rootProject = Some(main)

sbt not recognizing test

I am having difficulties getting sbt (version 0.12.1) to recognize any tests in src/test/scala.
I have tried both JUnit style tests and scalatest style tests but to no avial
To make things simple
I have moved my tests to the root package (src/test/scala)
I have included both org.scalatest and junit-interface in my build.sbt
libraryDependencies ++= List(
"org.scalatest" %% "scalatest" % "1.8" % "test",
"com.novocode" % "junit-interface" % "0.8" % "test->default"
)
I have made the tests as simple as possible:
scalatest example
import org.scalatest.FunSuite
import scala.collection.mutable.Stack
class ExampleSuite extends FunSuite {
test("math still works") {
assert(1+1 == 2)
}
}
junit test example:
import org.junit.Assert._
import org.junit.Test
class SimpleTest {
#Test
def testPass() {
assertEquals(1+1, 2)
}
}
my test structure is:
src/test/scala
├── FunSuiteExample.scala
└── SimpleTest.scala
What am I missing?
based on instructions at:
https://github.com/szeiger/junit-interface
modfied build.sbt
removed "junit" % "junit" % "4.10" % "test" from build.sbt
added "com.novocode" % "junit-interface" % "0.11" % "test"
put test in src/test/scala
import org.junit._
import org.junit.Assert._
class SimpleTeset {
#Test
def testTrue() {
assertEquals(1+1, 2)
}
}