gpt4 book ai didi

sbt - 播放 2.3.8 sbt 不包括 logback

转载 作者:行者123 更新时间:2023-12-02 11:22:04 24 4
gpt4 key购买 nike

我很难将 logback 从我的 play 2.3.8 测试运行中排除。我尝试了很多排除规则,但似乎没有任何效果。我在我的依赖树中也找不到它。我的 sbt 文件中的片段:

[...]
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"))
}

由于某种原因它不在依赖关系树中:

$ activator "inspect tree test" |grep -i qos |wc -l
0
$ activator "inspect tree test" |grep -i logback |wc -l
0

但是,当我运行测试时,它出现了!

$ 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]

我已经束手无策了。帮助。

最佳答案

我发现将排除项链接到添加库依赖项不起作用,即

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.~= 函数 ( http://www.scala-sbt.org/0.13.12/api/index.html#sbt.SettingKey ) 在下一行添加排除项,即

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-classic 和 slf4j。

请注意,您可以链接 except 和 exciteAll 方法调用以避免重复调用 map,以便您的代码可以简化为:

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 文件之前,libraryDependency 已经包含来自 Play 插件的 logback-classic。您可以排除plugin.sbt中的库,但如果您通过 enablePlugins(PlayScala)( https://www.playframework.com/documentation/2.5.x/NewApplication ) 使用 PlayScala 插件,则无法排除此库,因此您必须单独添加排除项。

关于sbt - 播放 2.3.8 sbt 不包括 logback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com