asciidoctorj库不适用于Spring Boot 2可执行启动jar

时间:2018-07-19 00:52:15

标签: spring-boot gradle-plugin asciidoctor

我尝试在Spring Boot 2.0.3中使用asciidoctorj,当我从IntelliJ IDEA运行项目时,一切正常,但是当我创建启动jar时,我开始看到以下错误:

Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- asciidoctor
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:956) ~[jruby-complete-9.1.16.0.jar!/:na]
    at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55) ~[na:na]
    at RUBY.<main>(<script>:15) ~[na:na]

这是build.gradle的摘录

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

... committed few lines

springBoot {
    buildInfo()
}

bootJar {
    launchScript()
    mainClassName = "com.example.demo.DemoApplication"
    requiresUnpack 'org.jruby:jruby-complete', 'org.asciidoctor:asciidoctorj'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.asciidoctor:asciidoctorj:1.5.7')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

如果有人想看看我的项目,托管在这里

https://github.com/cancerian0684/spring-boot2-asciidoctorj

与Spring Boot 1.5.14一起使用时没有问题的相同代码。

1 个答案:

答案 0 :(得分:3)

从Spring Boot的Gradle插件的reference documentation

  

要处理任何有问题的库,可以将可执行归档文件配置为在运行可执行归档文件时将特定的嵌套jar解压缩到一个临时文件夹中。可以使用与源jar文件的绝对路径匹配的Ant样式模式将库标识为需要解压缩。

然后,文档提供了匹配jruby-complete的示例:

bootJar {
    requiresUnpack '**/jruby-complete-*.jar'
}

**意味着该模式将匹配,而与包含jar的目录无关。该jar的名称实际上是jruby-complete-9.1.16.0.jar,但是模式中的*表示该模式将匹配该jar的任何版本。 AsciidoctorJ jar的等效模式为**/asciidoctorj-*.jar

综合起来,您的bootJar任务应配置如下:

bootJar {
    launchScript()
    mainClassName = "com.example.demo.DemoApplication"
    requiresUnpack '**/jruby-complete*.jar', '**/asciidoctorj-*.jar'
}

为帮助弄清源路径是什么,因此是什么合适的模式,您可以利用requiresUnpack也将闭包这一事实。从文档中:

  

要获得更多控制,也可以使用闭包。闭包传递了FileTreeElement,并应返回一个布尔值,指示是否需要拆包。

您可以使用以下临时配置运行构建,以查看要添加到jar中的所有文件的路径:

requiresUnpack {
    println it.file
    return false
}

您将看到类似于以下内容的输出:

/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-web/2.0.3.RELEASE/41fd4180bea3813de8f3c602b5a126218360315b/spring-boot-starter-web-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj/1.5.7/8e8c1d8fc6144405700dd8df3b177f2801ac5987/asciidoctorj-1.5.7.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-json/2.0.3.RELEASE/2e389a8727588c549c28bb277f0f573f65554850/spring-boot-starter-json-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter/2.0.3.RELEASE/ffaa050dbd36b0441645598f1a7ddaf67fd5e678/spring-boot-starter-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-tomcat/2.0.3.RELEASE/25a51a75bfb997b7b95d6760178ee3303863ec4b/spring-boot-starter-tomcat-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.hibernate.validator/hibernate-validator/6.0.10.Final/4236051a8d209c00f85e70918d5e26d9f3e5201e/hibernate-validator-6.0.10.Final.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-webmvc/5.0.7.RELEASE/751c871527ec7ff335ffc76f2e737e297c0a8d30/spring-webmvc-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-web/5.0.7.RELEASE/2e04c6c2922fbfa06b5948be14a5782db168b6ec/spring-web-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.jruby/jruby-complete/9.1.16.0/dfadacbdecc9c93a13871cc8242b92394d71631f/jruby-complete-9.1.16.0.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.35/47592e181b0bdbbeb63029e08c5e74f6803c4edd/jcommander-1.35.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.0.3.RELEASE/11bc4cc96b08fabad2b3186755818fa0b32d83f/spring-boot-autoconfigure-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.0.3.RELEASE/b874870d915adbc3dd932e19077d3d45c8e54aa0/spring-boot-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-logging/2.0.3.RELEASE/7caad34f01d2688919e15e09a90467963e3d5190/spring-boot-starter-logging-2.0.3.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/javax.annotation/javax.annotation-api/1.3.2/934c04d3cfef185a8008e7bf34331b79730a9d43/javax.annotation-api-1.3.2.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/5.0.7.RELEASE/243a23f8968de8754d8199d669780d683ab177bd/spring-context-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/5.0.7.RELEASE/fdd0b6aa3c9c7a188c3bfbf6dfd8d40e843be9ef/spring-aop-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.0.7.RELEASE/c1196cb3e56da83e3c3a02ef323699f4b05feedc/spring-beans-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/5.0.7.RELEASE/ca01fb473f53dd0ee3c85663b26d5dc325602057/spring-expression-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.0.7.RELEASE/54b731178d81e66eca9623df772ff32718208137/spring-core-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.19/2d998d3d674b172a588e54ab619854d073f555b5/snakeyaml-1.19.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.9.6/456895fc91bf7180b216fead220373e6278230c9/jackson-datatype-jdk8-2.9.6.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.9.6/ea54f6193d224e5e5732bbd4262327eb465397c2/jackson-datatype-jsr310-2.9.6.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.module/jackson-module-parameter-names/2.9.6/129acd77a4b6ee30d62d3a0899b1344c8ec2bff8/jackson-module-parameter-names-2.9.6.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.9.6/cfa4f316351a91bfd95cb0644c6a2c95f52db1fc/jackson-databind-2.9.6.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-websocket/8.5.31/6564e716b89de5eaa0dd234ae7989576503ddf3/tomcat-embed-websocket-8.5.31.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/8.5.31/f5adf7ed8c34aa005b22b6a2dc7b6796e10e9c79/tomcat-embed-core-8.5.31.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-el/8.5.31/3a536e1ac71b82627c3a7408eb38fa0704cb9034/tomcat-embed-el-8.5.31.jar
/Users/username/.gradle/caches/modules-2/files-2.1/javax.validation/validation-api/2.0.1.Final/cb855558e6271b1b32e716d24cb85c7f583ce09e/validation-api-2.0.1.Final.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.jboss.logging/jboss-logging/3.3.2.Final/3789d00e859632e6c6206adc0c71625559e6e3b0/jboss-logging-3.3.2.Final.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml/classmate/1.3.4/3d5f48f10bbe4eb7bd862f10c0583be2e0053c6/classmate-1.3.4.jar
/Users/username/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-to-slf4j/2.10.0/f7e631ccf49cfc0aefa4a2a728da7d374c05bd3c/log4j-to-slf4j-2.10.0.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.slf4j/jul-to-slf4j/1.7.25/af5364cd6679bfffb114f0dec8a157aaa283b76/jul-to-slf4j-1.7.25.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.0.7.RELEASE/699016ddf454c2c167d9f84ae5777eccadf54728/spring-jcl-5.0.7.RELEASE.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.9.0/7c10d545325e3a6e72e06381afe469fd40eb701/jackson-annotations-2.9.0.jar
/Users/username/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.9.6/4e393793c37c77e042ccc7be5a914ae39251b365/jackson-core-2.9.6.jar
/Users/username/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.2.3/864344400c3d4d92dfeb0a305dc87d953677c03c/logback-core-1.2.3.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.25/da76ca59f6a57ee3102f8f9bd9cee742973efa8a/slf4j-api-1.7.25.jar
/Users/username/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.10.0/fec5797a55b786184a537abd39c3fa1449d752d6/log4j-api-2.10.0.jar

Ant样式的模式必须匹配这些路径,以便罐子被标记为需要拆箱。