2

在 Windows 上使用 asciidoctor-maven-plugin 时,我们在弹出目标 process-asciidocs 时遇到编码不兼容错误。

我们已经尝试使用插件的 0.1.4 版本和 master 的最新 SNAPSHOT。

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.asciidoctor:asciidoctor-maven-plugin:1.5.0-SNAPSHOT:process-asciidoc (default-cli) on project lgtdev-doc: Execution default-cli of goal org.asciido
ctor:asciidoctor-maven-plugin:1.5.0-SNAPSHOT:process-asciidoc failed: (Encoding::CompatibilityError) incompatible character encodings: CP850 and UTF-8
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.asciidoctor:asciidoctor-maven-plugin:1.5.0-SNAPSHOT:process-asciidoc failed: (Encoding::CompatibilityError) incompatible character enco
dings: CP850 and UTF-8
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
Caused by: org.jruby.exceptions.RaiseException: (Encoding::CompatibilityError) incompatible character encodings: CP850 and UTF-8
        at org.jruby.RubyString.concat(org/jruby/RubyString.java:2636)
        at RUBY.result((erb):58)
        at org.jruby.RubyKernel.eval(org/jruby/RubyKernel.java:1093)
        at RUBY.result(jar:file:/C:/Users/AUX7010/.m2/repository/org/jruby/jruby-complete/1.7.4/jruby-complete-1.7.4.jar!/META-INF/jruby.home/lib/ruby/1.9/erb.rb:838)
        at RUBY.render(jar:file:C:/Users/AUX7010/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar!/gems/asciidoctor-0.1.4/lib/asciidoctor/backends/base_template.rb:55)
        at RUBY.render(jar:file:C:/Users/AUX7010/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar!/gems/asciidoctor-0.1.4/lib/asciidoctor/renderer.rb:137)
        at RUBY.render(jar:file:C:/Users/AUX7010/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar!/gems/asciidoctor-0.1.4/lib/asciidoctor/document.rb:769)
        at RUBY.render(jar:file:C:/Users/AUX7010/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar!/gems/asciidoctor-0.1.4/lib/asciidoctor.rb:915)
        at RUBY.render_file(jar:file:C:/Users/AUX7010/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar!/gems/asciidoctor-0.1.4/lib/asciidoctor.rb:993)
        at RUBY.render_file(<script>:51)
        at org.jruby.gen.InterfaceImpl1306937631.render_file(org/jruby/gen/InterfaceImpl1306937631.gen:13)

将 cruby 与 asciidoctor gem 一起使用时,我们没有收到此错误,因此它认为问题出在 jruby 执行环境上。

在 Mac 上,我们通过设置 JAVA_TOOL_OPTIONS="-DFile=encoding.UTF-8" 解决了同样的错误,但在 Windows 上这不起作用。

我们如何强制 jruby 使用 UTF-8?

4

1 回答 1

3

我们通过编辑 asciidoctor-java-integration jar 中的 asciidoctor 源解决了这个问题,在 gems/asciidoctor-0.1.4/lib/asciidoctor.rb 中强制 Encoding.default_external = Encoding::UTF_8。虽然不是一个优雅的解决方案,但它可以工作。

于 2014-04-08T08:16:57.180 回答