Build.scala, % and %% symbols meaning

社会主义新天地 提交于 2019-11-26 11:59:15

问题


I\'m new to Play! Framework 2.1 (java version) and have no experience with scala. I don\'t understand what are and what does % and %% mean in Build.scala. I googled about them but couldn\'t find their meaning.

In my Build.scala file I have:

\"org.hibernate\" % \"hibernate-entitymanager\" % \"4.1.0.Final\",
\"com.typesafe\" %% \"play-plugins-mailer\" % \"2.1\"

Why the first line uses a single % symbol and the second one uses two percent symbols %%? What are they for?


回答1:


From the official documentation:

http://www.playframework.com/documentation/2.1.1/SBTDependencies

Getting the right Scala version with %%

If you use groupID %% artifactID % revision instead of groupID % artifactID % revision (the difference is the double %% after the groupID), SBT will add your project’s Scala version to the artifact name. This is just a shortcut.

You could write this without the %%:

val appDependencies = Seq(
  "org.scala-tools" % "scala-stm_2.9.1" % "0.3"
)

Assuming the scalaVersion for your build is 2.9.1, the following is identical:

val appDependencies = Seq(
  "org.scala-tools" %% "scala-stm" % "0.3"
)

As you can see above, if you use %%, you don't have to specify the version.




回答2:


This is part of SBT which play uses as a build tool. Specifically this is an import statement.

The percent symbol % is a actually a method used to build dependencies. The double percent sign %% injects the current Scala version - this allows you to get the correct library for the version of scala you are running. This is to avoid having to change your build file when you update Scala.

More information here



来源:https://stackoverflow.com/questions/17461453/build-scala-and-symbols-meaning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!