为 SBT 依赖项设置 javac 选项 [英] Setting javac options for SBT dependencies

查看:27
本文介绍了为 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 收到的错误是:

The error I am receiving from sbt compile is:

[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).

这篇关于为 SBT 依赖项设置 javac 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆