在Windows上使用asciidoctor-maven-plugin时,我们在执行目标进程时会遇到编码不兼容错误-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 =&#34; -DFile = encoding.UTF-8&#34;解决了同样的错误。但在Windows上这没有效果。
我们怎样才能强迫jruby使用UTF-8?
答案 0 :(得分:3)
我们通过编辑asciidoctor-java-integration jar中的asciidoctor源解决了这个问题,强制gems / asciidoctor-0.1.4 / lib / asciidoctor.rb中的Encoding.default_external = Encoding :: UTF_8。虽然不是一个优雅的解决方案,但它有效。