【问题标题】:Scala/Java Project not finding Dependencies during Maven compileScala/Java 项目在 Maven 编译期间未找到依赖项
【发布时间】:2016-05-18 10:30:59
【问题描述】:

我有一个 Java/Scala 混合项目。在 Intellij 中构建时,一切正常。但是,尝试从命令行运行 Maven 构建会在运行“mvn clean install”时出现此错误:

    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:12: error: object model is not a member of package com.test.userlib
    [ERROR] import com.test.userlib.model.cte.{ItemResponse, CteUser}
    [ERROR]                                      ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:13: error: object utils is not a member of package com.test.userlib
    [ERROR] import com.test.userlib.utils.UserLibProperties
    [ERROR]                                      ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:26: error: not found: value UserLibProperties
    [ERROR]       .hosts(UserLibProperties.CTE_USERSERVICE_HOST + ":" + UserLibProperties.CTE_USERSERVICE_PORT)
    [ERROR]              ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:32: error: not found: value UserLibProperties
    [ERROR]     ClientAuthTlsConfigUtil.createSslContext(new File(UserLibProperties.CTE_USERSERVICE_KEYSTORE),UserLibProperties.CTE_USERSERVICE_KEYSTORE_PASSWORD,new File(UserLibProperties.CTE_USERSERVICE_TRUSTSTORE),UserLibProperties.CTE_USERSERVICE_TRUSTSTORE_PASSWORD)
    [ERROR]                                                       ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:35: error: not found: type CteUser
    [ERROR]   protected def getUser(dn :String) :CteUser = {
    [ERROR]                                      ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:36: error: not found: value UserLibProperties
    [ERROR]     val rb = RequestBuilder().url(s"${UserLibProperties.CTE_USERSERVICE_ENDPOINT}/user?dn=${URLEncoder.encode(dn,"utf-8")}&aacAttribs=true").buildGet
    [ERROR]                                       ^
    [ERROR] /IdeaProjects/user-lib-common/src/main/scala/com/test/userlib/rest/UserServiceRestClient.scala:42: error: not found: type ItemResponse
    [ERROR]       case HttpResponseStatus.OK => new ObjectMapper().readValue(respTry.get.getContent.toString("UTF-8"), classOf[ItemResponse]).getItem.getUser
    [ERROR]                                                                                                                    ^
    [ERROR] 7 errors found

所以,很明显我的 Scala 类没有找到它需要的 Java 依赖项。这是我的项目结构:

这是我的 pom.xml 的构建部分:

   <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

我必须以某种方式将类路径添加到 Scala 编译器吗?

【问题讨论】:

  • 你当时解决了这个问题吗?我知道它是前一段时间的,但是在一些依赖项更改后我突然遇到了同样的问题(很多人需要单独检查......)

标签: java scala maven


【解决方案1】:

我认为 UserLibProperties 文件应该在正确的文件扩展名 UserLibProperties.scala 中。请检查您的文件夹并执行列表命令并检查文件扩展名,在 Intelij 中它可以在没有适当扩展名的情况下工作。

【讨论】:

    【解决方案2】:

    我认为,SBT 是构建混合项目的最佳方式。

    例如: https://github.com/databricks/learning-spark/blob/master/build.sbt

    它的学习曲线很小,但值得花时间在 SBT 上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-22
      • 1970-01-01
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      相关资源
      最近更新 更多