I use playframework2.2: try to build a play support project.
in my Build.scala, I want to add play.Project.playJavaSetting:
val main = play.Project(appName, appVersion, appDependencies)
.settings(play.Project.playJavaSettings) //error here
.settings(
resolvers += "webjars" at "http://webjars.github.com/m2",
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/release"
)
the error is:
[error] F:\git\play-example-form\project\Build.scala:19: overloaded method value
settings with alternatives:
[error] (ss: sbt.Def.Setting[_]*)sbt.Project <and>
[error] => Seq[sbt.Def.Setting[_]]
[error] cannot be applied to (Seq[sbt.Setting[_]])
[error] .settings(play.Project.playJavaSettings)
[error] ^
If I do not add playJavaSetting, it give me error about wrong collection apply, I mean:
val main = play.Project(appName, appVersion, appDependencies)
//.settings(play.Project.playJavaSettings)
and the error is:
[error] required: play.api.data.Form<StudentFormData>,scala.collection.immutab
le.Map<String,Object>,scala.collection.immutable.List<String>,scala.collection.i
mmutable.Map<String,Object>,scala.collection.immutable.Map<String,Object>
[error] found: play.data.Form<StudentFormData>,java.util.Map<String,Boolean>,j
ava.util.List<String>,java.util.Map<String,Boolean>,java.util.Map<String,Boolean
you can see the framework apply the scala.collection.immutable.List instead of play.util.List, If I really want to apply the java collections how to set the environment setting in Build.scala file?
You should change
.settings(play.Project.playJavaSettings)
to
.settings(play.Project.playJavaSettings: _*)
The settings method is declared as def settings(ss: Setting[_]*), which means it takes repeated parameters of type Setting[_]. The play.Project.playJavaSettings is of type Seq[Setting[_]]. To convert one to another Scala has a special type annotation.
If you are interested in details check 4.6.2 Repeated Parameters of The Scala Language Specification
Related
The project I'm working on uses Scala and SBT. I need to introduce the use of a deprecated method in our code and rather than just giving me an error, sbt is giving me a compile error when I try and compile the code.
Is there a flag or setting somewhere that makes this happen that I can change?
method getDB in class Mongo is deprecated: see corresponding Javadoc
for more information.
[error] lazy val db: com.mongodb.DB = mongoClient.getDB("foo")
[error] ^
[error] one error found
[error] (web/compile:compileIncremental) Compilation failed
[error] Total time: 9 s, completed Jun 2, 2017 7:20:53 AM
Thanks.
SBT gives you a lot of options to set depreciation warnings as errors.
set scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation", "-Xfatal-warnings")
OR
sbt compile -deprecation
OR
You can configure the same in build.sbt file.
You'll have to remove any of the above options if you are using. (Check your compiler settings)
Also, do sbt clean reload compile.
This worked for me.
Scalac has a flag Xfatal-warnings that turns warnings into errors. See Is there a way in sbt to convert compiler warnings to errors so the build fails? and https://github.com/scala/bug/issues/8410
A workaround is defining a deprecated trait that calls the method and making its companion object implement that trait:
scala> #deprecated("","") def foo = "I am deprecated"
foo: String
scala> #deprecated("","") trait Foo { def safeFoo = foo }; object Foo extends Foo
defined trait Foo
defined object Foo
scala> foo
<console>:13: warning: method foo is deprecated:
foo
^
res0: String = I am deprecated
scala> Foo.safeFoo
res1: String = I am deprecated
In your build.sbt you can set scalaOptions as below :
lazy val exScalacOptions: Seq[String] = Seq(
"-Xlint",
"-feature",
"-deprecation:false",
"-unchecked"
)
After setting the above value you can reference it in your project module settings in build.sbt as below:
scalacOptions := exScalacOptions
This question already has answers here:
Maven archetype - Velocity error because of a colon
(3 answers)
Closed 6 years ago.
I am trying to default some property values in a templated class and it looks like the velocity engine the maven archtype plugin is using is choking on the ':' with errors like:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:generate (default-cli) on project standalone-pom: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered ":" at line 18, column 40 of archetype-resources/__modelName__/src/main/java/client/CandyClientConfig.java
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR]
I have tried several escape sequences and it complains about them all:
#Value("${candy.http.maxConnections\:100}")
#Value("${candy.http.maxConnections\\:100}")
#Value("${candy.http.maxConnections:100}")
in the top of my archetype pom
#set($colon = ':')
then
#Value("${candy.http.maxConnections$colon100}")
This should be easily to beat. So, what am I missing?
I faced the same issue in the past, the problem lies in the common syntax ${...} used by velocity and the java code.
Though I don't consider it a particularly elegant solution, I solved the problem as follows:
#set( $candy_http_max_connections_decl = '${candy.http.maxConnections:100}')
#Value("${candy_http_max_connections_decl}")
PS. To keep the code readable in case of many of such declarations in my source file, I kept the #set declarations close to their use (in the example, the line immediately above the #Value(...) annotation), instead of putting them at the beginning of the file as I would have normally done
If you address the '$' character instead of ':', like in :
#set( $dollar = '$' )
then
#Value("${dollar}{candy.http.maxConnections:100}")
it seems to work
I'm making an web app using GWT i18n. In this app, I would like to set up a custom property files to support differences from main language. For example I have an en_US locale, but also I would like to have en_US_x_custom support with some redefined property fields (specifications of BCP 47 says that I can use -x tag for private tag support).
Let me show what I have for now:
I have an interface
public interface TestMsg extends Messages {
String value();
}
and few property files:
TestMsg_en_US.properties
TestMsg_en_US_x_custom.properties
In app.gwt.xml, I have this lines
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name="com.google.gwt.i18n.CldrLocales"/>
<extend-property name="locale" values="en_US"/>
<extend-property name="locale" values="en_US_x_custom"/>
However, the problem is that compilations fails with following messages:
[ERROR] Type com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom could not be referenced because it previously failed to compile with errors:
Tracing compile failure path for type 'com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom'
[ERROR] Errors in 'generated://74EF808C0035420F02374EADB97661B8/com/google/gwt/i18n/client/impl/LocaleInfoImpl_en_US_X-custom.java'
[ERROR] Line 10: Syntax error on token "-", < expected
[ERROR] Line 17: The method getLocaleQueryParam() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 10: The public type LocaleInfoImpl_en_US_X must be defined in its own file
[ERROR] Line 22: The method getDateTimeFormatInfo() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 10: Syntax error, insert "AdditionalBoundList1" to complete TypeParameter1
[ERROR] Line 27: The method getNumberConstants() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 12: The method getLocaleName() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Errors in 'com/google/gwt/i18n/client/LocaleInfo.java'
[ERROR] Line 37: Rebind result 'com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom' could not be found
How do I get rid of this compilation error? How can I fix this problem?
You can ommit -x part of the locale. Then you can specify the locale as en_US_custom and have property file named TestMsg_en_US_CUSTOM.properties (notice capital letters).
The following error appear when I'm using NavigableSet to get the decending key set of a TreeMap:
[ERROR] [workflow] - Line 159: No source code is available for type java.util.NavigableSet<E>; did you forget to inherit a required module?
[ERROR] [workflow] - Line 159: The method descendingKeySet() is undefined for the type TreeMap<Integer,String>
Here is the code I use:
NavigableSet<Integer> nmap = selectedRow.descendingMap();
Does someone know where the error comes from ?
(For information i've imported the right class: java.util.NavigableSet )
I don't have enough rep for a comment... sorry. What version of GWT are you using? It looks like there is a bug here:
https://code.google.com/p/google-web-toolkit/issues/detail?id=4236
Fixed in 2.7.0 RC1
I saw a few questions about this topic, but none answer the part I am stuck on. By the way, based on the issues people are running into, I might suggest giving a default java implementation of the TemplatesPlugin after all.
The problem I have, is that I copied the two needed views from SecureSocial to my views folder, and changed the RequestHeader as others have noted to: play.api.mvc.RequestHeader and now I am getting:
ambiguous implicit values: both method requestHeader in object PlayMagicForJava of type => play.api.mvc.RequestHeader and value request of type play.api.mvc.RequestHeader match expected type play.api.mvc.RequestHeader
Version: Play-2.1.1, Java 7, SecureSocial from Master.
EDIT:
Play Compile:
[error] C:\Java\AwsConsole\app\views\secure\login.scala.html:41: ambiguous impli
cit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] #provider(p.id)
[error] ^
[error] C:\Java\AwsConsole\app\views\secure\provider.scala.html:20: ambiguous im
plicit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] <form action = "#securesocial.core.providers.utils.Route
sHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)"
[error]
^
[error] two errors found
[error] (compile:compile) Compilation failed
Browsing after Play Run instead:
Internal server error, for (GET) [/] ->
sbt.PlayExceptions$CompilationException: Compilation error[ambiguous implicit va
lues:
both method requestHeader in object PlayMagicForJava of type => play.api.mvc.Re
questHeader
and value request of type play.api.mvc.RequestHeader
match expected type play.api.mvc.RequestHeader]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:346) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
The request must be passed explicitely to the login template, the login template must pass the request explicitely to the provider template and the provider template must specify the request when invoking RoutesHelper.authenticateByPost("userpass").absoluteURL. More detailed:
The java TemplatesPlugin should have this getLoginPage implementation:
#Override
public <A> Html getLoginPage(final play.api.mvc.Request<A> request, final Form<Tuple2<String, String>> form,
final Option<String> msg) {
return views.html.login.render(request, form, msg);
}
The parameters (first line) of login.scala.html should look like this:
#(request: play.api.mvc.RequestHeader, loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)
Change calls from login.scala.html to the provider template to pass the request explicitely (we'll adjust its parameters in the next step).
login.scala.html line 41, change
#provider(p.id)
to
#provider(request, p.id)
login.scala.html line 55, change
#provider("userpass", Some(loginForm))
to
#provider(request, "userpass", Some(loginForm))
The parameters (first line) of provider.scala.html should take the request as first, explicit parameter:
#(request: play.api.mvc.RequestHeader, providerId: String, loginForm: Option[play.api.data.Form[(String, String)]] = None)
Line 20 of the provider template needs to pass the request (so that the correct method is invoked, otherwise you'll get a RuntimeException: There is no HTTP Context available from here):
<form action = "#securesocial.core.providers.utils.RoutesHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)(request)"
This should be all needed changes, if you're using other templates they would have to be adjusted accordingly.
Just to mentiond it: I had changed our java TemplatesPlugin to a scala version (to have it more straight forward).