Scala/Java项目在Maven编译期间未找到依赖项
我有一个Java/Scala混合项目。在Intellij中构建时,一切正常。但是,尝试从命令行运行Maven构建在运行“mvn clean install”时会出现以下错误:Scala/Java项目在Maven编译期间未找到依赖项,java,scala,maven,Java,Scala,Maven,我有一个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.
[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>
src/main/scala
src/test/scala
org.apache.maven.plugins
maven编译器插件
1.8
1.8
net.alchim31.maven
scala maven插件
scala先编译
过程资源
添加源
编译
scala测试编译
过程测试资源
测试编译
我是否必须以某种方式将类路径添加到Scala编译器中?我认为,SBT是构建混合项目的最佳方式 例如:
它几乎没有学习曲线,但值得在SBT上投入时间 我认为UserLibProperties文件的扩展名应该是UserLibProperties.scala。请检查您的文件夹,并执行列表命令,检查文件扩展名,在Intelij中,它将在没有正确扩展名的情况下工作