Scala中的PureConfig ConfigLoader

时间:2019-05-27 09:00:43

标签: scala pureconfig

我正在跟踪此链接以使用pureconfig加载数据 https://pureconfig.github.io/docs/overriding-behavior-for-case-classes.html。 这是我的代码

import com.typesafe.config.ConfigFactory
import pureconfig._
private case class SampleConf(foo: Int, bar: String)
object TestConfigLoad {
  def main(args: Array[String]): Unit = { 
    loadConfig[SampleConf](ConfigFactory.parseString("{ FOO: 2, BAR: two }"))
  }
}

运行它时,出现此错误

Error:scalac: Error: scala.collection.immutable.$colon$colon.tl$1()Lscala/collection/immutable/List;
java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.tl$1()Lscala/collection/immutable/List;
    at shapeless.LazyMacros$DerivationContext$State.addDependency(lazy.scala:363)

这些是pom文件中的条目

        <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
                     <version>2.11.7</version>
                </dependency>
                <dependency>
                    <groupId>org.scala-tools</groupId>
                    <artifactId>maven-scala-plugin</artifactId>
                    <version>2.15.2</version>
                </dependency>
                <dependency>
                    <groupId>com.github.pureconfig</groupId>
                    <artifactId>pureconfig_2.11</artifactId>
                    <version>0.8.0</version>
                </dependency>
           <dependency>

            <groupId>org.clapper</groupId>
            <artifactId>grizzled-slf4j_2.11</artifactId>
            <version>1.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.9</version>
        </dependency>

        <dependency>
            <groupId>com.lihaoyi</groupId>
            <artifactId>sourcecode_2.11</artifactId>
            <version>0.1.4</version>
        </dependency>

1 个答案:

答案 0 :(得分:2)

您必须匹配Scala版本。无法混合2.10(scala-library)和2.11(pureconfig_2.11)。

除非有充分的理由,否则请使用最新的稳定版本(当前为2.12.8)