播放2.3.8 sbt,不包括登录 [英] play 2.3.8 sbt excluding logback
问题描述
在我的游戏2.3.8测试运行中,除了logback
之外,我很难过.我尝试了许多排除规则,但似乎没有任何效果.我也无法在我的依赖树中找到它.我的sbt文件中的代码段:
I'm having a really hard time excluding logback
from my play 2.3.8 test run. I've tried many exclude rules, but nothing seems to work. I also can't find it in my dependency tree. Snippet from my sbt file:
[...]
resolvers ++= Seq(
"Typesafe repository snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
"Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
"Sonatype repo" at "https://oss.sonatype.org/content/groups/scala-tools/",
"Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases",
"Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype staging" at "http://oss.sonatype.org/content/repositories/staging",
"Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
"Twitter Repository" at "http://maven.twttr.com",
"Websudos releases" at "http://maven.websudos.co.uk/ext-release-local"
)
libraryDependencies ++= {
val phantomVersion = "1.5.0"
Seq(
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.xerial.snappy" % "snappy-java" % "1.1.1.6",
"com.websudos" %% "phantom-dsl" % phantomVersion,
"com.websudos" %% "phantom-testing" % phantomVersion % Test,
"org.scalatestplus" %% "play" % "1.2.0" % Test,
"org.cassandraunit" % "cassandra-unit" % "2.1.3.1" % Test
).map(_.exclude("org.slf4j", "slf4j-jdk14"))
.map(_.excludeAll(ExclusionRule(organization = "ch.qos.logback")))
.map(_.excludeAll(ExclusionRule(organization = "QOS.ch")))
.map(_.excludeAll(ExclusionRule(artifact = "logback*")))
.map(_.excludeAll(ExclusionRule(artifact = "logback-classic")))
.map(_.exclude("ch.qos.logback", "logback-parent"))
.map(_.exclude("ch.qos.logback", "logback-core"))
.map(_.exclude("QOS.ch", "logback-parent"))
.map(_.exclude("", "logback-classic"))
}
由于某种原因,它不在依赖树中:
It's not in the dependency tree for some reason:
$ activator "inspect tree test" |grep -i qos |wc -l
0
$ activator "inspect tree test" |grep -i logback |wc -l
0
但是,当我运行测试时,它会显示出来!
Yet, when I run the test, it shows up!
$ activator test
[...]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/X/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/X/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
我在机智的尽头.帮助.
I'm at my wits' end. Help.
推荐答案
我发现将排除项链接到增加的libraryDependencies上是行不通的,即
I have found that chaining the exclusions to the addition of libraryDependencies does not work, i.e.
libraryDependencies ++= {
val phantomVersion = "1.5.0"
Seq(
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.xerial.snappy" % "snappy-java" % "1.1.1.6",
"com.websudos" %% "phantom-dsl" % phantomVersion,
"com.websudos" %% "phantom-testing" % phantomVersion % Test,
"org.scalatestplus" %% "play" % "1.2.0" % Test,
"org.cassandraunit" % "cassandra-unit" % "2.1.3.1" % Test
).map(_.exclude("org.slf4j", "slf4j-jdk14"))
.map(_.excludeAll(ExclusionRule(organization = "ch.qos.logback")))
.map(_.excludeAll(ExclusionRule(organization = "QOS.ch")))
.map(_.excludeAll(ExclusionRule(artifact = "logback*")))
.map(_.excludeAll(ExclusionRule(artifact = "logback-classic")))
.map(_.exclude("ch.qos.logback", "logback-parent"))
.map(_.exclude("ch.qos.logback", "logback-core"))
.map(_.exclude("QOS.ch", "logback-parent"))
.map(_.exclude("", "logback-classic"))
}
相反,请使用未记录的SettingKey.~=
函数添加排除项(
Instead, add the exclusions using the undocumented SettingKey.~=
function (http://www.scala-sbt.org/0.13.12/api/index.html#sbt.SettingKey) on the following line after adding new dependencies, i.e.
libraryDependencies ++= {
val phantomVersion = "1.5.0"
Seq(
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.xerial.snappy" % "snappy-java" % "1.1.1.6",
"com.websudos" %% "phantom-dsl" % phantomVersion,
"com.websudos" %% "phantom-testing" % phantomVersion % Test,
"org.scalatestplus" %% "play" % "1.2.0" % Test,
"org.cassandraunit" % "cassandra-unit" % "2.1.3.1" % Test
)
libraryDependencies ~= { _.map(_.exclude("org.slf4j", "slf4j-jdk14"))
.map(_.excludeAll(ExclusionRule(organization = "ch.qos.logback")))
.map(_.excludeAll(ExclusionRule(organization = "QOS.ch")))
.map(_.excludeAll(ExclusionRule(artifact = "logback*")))
.map(_.excludeAll(ExclusionRule(artifact = "logback-classic")))
.map(_.exclude("ch.qos.logback", "logback-parent"))
.map(_.exclude("ch.qos.logback", "logback-core"))
.map(_.exclude("QOS.ch", "logback-parent"))
.map(_.exclude("", "logback-classic"))
}
我不知道为什么会给出不同的行为,但是使用Play Framework 2.4.3和SBT 0.13.8可以成功排除经典的logback和slf4j.
I don't know why this gives different behaviour, but with Play Framework 2.4.3 and SBT 0.13.8 this successfully excludes logback-classic and slf4j.
请注意,您可以链接exclude和excludeAll方法调用,以避免重复调用map
,因此您的代码可以简化为:
Note that you can chain exclude and excludeAll method calls to avoid repeatedly calling map
so your code can be simplified to:
libraryDependencies ++= {
val phantomVersion = "1.5.0"
Seq(
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.xerial.snappy" % "snappy-java" % "1.1.1.6",
"com.websudos" %% "phantom-dsl" % phantomVersion,
"com.websudos" %% "phantom-testing" % phantomVersion % Test,
"org.scalatestplus" %% "play" % "1.2.0" % Test,
"org.cassandraunit" % "cassandra-unit" % "2.1.3.1" % Test
)
libraryDependencies ~= { _.map(_
.exclude("org.slf4j", "slf4j-jdk14"))
.exclude("ch.qos.logback", "logback-classic"))
}
经过进一步调查,我认为这是必需的,因为在解析build.sbt文件之前,libraryDependencies已经包含来自Play插件的经典logback.您可以排除plugin.sbt中的库,但是如果您使用的是enablePlugins(PlayScala)
(
After further investigation, I believe that this is required because the libraryDependencies already contain logback-classic from the Play plugin prior to parsing the build.sbt file. You can exclude the libraries in plugin.sbt, but if you are using the PlayScala plugin by enablePlugins(PlayScala)
(https://www.playframework.com/documentation/2.5.x/NewApplication) this cannot be excluded so you have to add the exclusions separately.
这篇关于播放2.3.8 sbt,不包括登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!