Setting javac options for SBT dependencies

微笑、不失礼 提交于 2019-12-20 01:13:57

问题


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")
}

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 seems to be executing javac with an encoding that is incompatible with the source files in this dependency.

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 How do I get my Java dependencies compiling with the correct encoding?


回答1:


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")

You can verify that your options are being used with last. For example,

sbt> last compile

To run commands like the above on a project from git, change to it using project (see help project for details).



来源:https://stackoverflow.com/questions/21350739/setting-javac-options-for-sbt-dependencies

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!