为SBT依赖项设置Javac选项
我在编译通过GIT加载的Java依赖项时遇到问题:
I am having problems compiling a Java dependency loaded via GIT:
object ApplicationBuild extends Build {
lazy val project = Project("root", file(".")).dependsOn(RootProject(riakJavaClient))
lazy val riakJavaClient = uri("git://github.com/basho/riak-java-client")
}
我从sbt compile
收到的错误是:
[info] Compiling 134 Java sources to /Users/lawrencewagerfield/.sbt/0.13/staging/da0e66c4764a467c8977/riak-java-client/target/scala-2.10/classes...
[error] /Users/lawrencewagerfield/.sbt/0.13/staging/da0e66c4764a467c8977/riak-java-client/src/main/java/com/basho/riak/client/cap/Quorum.java:22: error: unmappable character for encoding ASCII
[error] * Riak 0.12 introduced ???symbolic??? consistency options for R and W
SBT似乎正在以与该依赖项中的源文件不兼容的编码来执行javac
.
SBT seems to be executing javac
with an encoding that is incompatible with the source files in this dependency.
我尝试将以下内容添加到build.sbt
,但没有效果(错误是相同的):
I have tried adding the following to build.sbt
, but it is having no effect (error is the same):
javacOptions ++= Seq("-encoding", "UTF-16") // Note: I have tried with UTF-8 too
以上内容仅适用于我项目中的源文件吗?知道如何解决此问题吗?
Does the above only apply to source files within my project? Any idea how to get pass this issue?
TL; DR 如何使用正确的编码来编译Java依赖项?
TL;DR How do I get my Java dependencies compiling with the correct encoding?
您正确的是,该设置仅适用于项目中的源文件.如果未指定范围的项目部分(通常是这样),则默认为封闭项目.要将设置应用于另一个项目,请将其范围限制到该项目.例如,
You are correct that the setting only applies to source files in your project. If the project part of the scope isn't specified, which is typical, it defaults to the enclosing project. To have a setting apply to another project, scope it to that project. For example,
javacOptions in riakJavaClient ++= Seq("-encoding", "UTF-8")
您可以验证您的选项是否与last
一起使用.例如,
You can verify that your options are being used with last
. For example,
sbt> last compile
要从git在项目上运行上述命令,请使用project
更改为该命令(有关详细信息,请参见help project
).
To run commands like the above on a project from git, change to it using project
(see help project
for details).