本文介绍了sbt添加java项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用IDEA IntelliJ中的一些scala软件. (如果必要,它还具有Android功能).假设我有两个项目:

Working on some scala software in IDEA IntelliJ. (It also features Android if it is essential). Suppose I have two projects:

用scala编写的P1使用sbt作为构建工具

P1, written in scala, uses sbt as the build tool

用Java编写的P2使用gradle作为构建工具

P2, written in java, uses gradle as the build tool

我想从P2调用一些代码,它具有完整的源代码.因此,我在IntelliJ scala项目中将P2导入为模块.但是,当我使用sbt-shell编译sbt项目时,它告诉我一个错误,即找不到在P2中声明的类和包的任何定义.我想我需要在build.sbt文件中创建适当的引用,以便它可以理解定义的来源.我找到了一种建议将非托管Java源路径添加到build.sbt的解决方案,如下所示:

I want to call some code from P2, having its full source. So I import P2 as a module in my IntelliJ scala project. But when I compile my sbt project using sbt-shell, it tells me an error that it cannot find any definitions of classes and packages declared in P2. I guess I need to create a proper reference in my build.sbt file so it could understand where the definitions come from. I've found one solution which suggests adding unmanaged java source paths to build.sbt like so:

unmanagedSourceDirectories in Compile += file("mydependency")

但是,依赖关系本身具有依赖关系.当我尝试编译该代码时,sbt告诉我它找不到该依赖项的定义.因此,我需要一种在build.sbt中引用完整Java项目的方法,以便随后可以通过sbt shell编译整个内容(实际上,我被迫使用了sbt shell).

but thing is that dependency has dependencies itself. When I try to compile that, sbt tells me that it cannot find definitions of that dependency. So I need a way to reference full java project in build.sbt so that I could then compille whole thing via sbt shell (in fact, I forced to use the very sbt shell).

有什么建议吗?

推荐答案

根据我的理解,更好(但不同)的解决方案是在您的本地存储库中发布jar(例如 publishLocal),并依赖它.

Per my understanding, better (but different) solution would be to publish jar in your local repository (e.g. publishLocal), and depend on it.

这篇关于sbt添加java项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:44