我有一个Spring应用程序,该应用程序集成了从java类触发的clara规则引擎(clojure)文件。使用gradle构建应用程序时,clojure文件不会作为JAR的一部分生成。
因此,在运行the jar时,它将引发以下异常:Caused by: java.io.FileNotFoundException: Could not locate au/com/acme/mti/mec/runtime/rules/mec__init.class or au/com/acme/mti/mec/runtime/rules/mec.clj on classpath.
在构建/生成jar时,使gradle生成clj文件的最佳方法(或至少一种方法)是什么?
我已经在build.gradle文件中包含一个任务,用于将clj文件从src路径复制到构建路径。它在构建路径下复制文件,但不在jar中。
build.gradle:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'jacoco'
}
group = 'au.com.acme.mti.mec'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
mavenLocal()
maven {
url "http://clojars.org/repo"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.clojure:clojure:1.9.0'
implementation 'com.cerner:clara-rules:0.20.0'
implementation 'org.projectlombok:lombok'
}
}
task copyRules(type: Copy){
from 'src/main/resources/au.com.acme.mti.mec.runtime.rules/'
into 'build/classes/java/main/au/com/acme/mti/mec/runtime/rules/'
}
test {
test.dependsOn copyRules
useJUnitPlatform()
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
最佳答案
将Clojure文件(Clara规则)放在一个最终位于JAR内正确位置的地方,这将使复制任务成为绝对的(不是用于构建JAR的-至少从build.gradle
的一部分开始)我们可以在问题中看到。
src/main/resources/au.com.acme.mti.mec.runtime.rules
移到src/main/resources/au/com/acme/mti/mec/runtime/rules
copyRules
任务(它是dependsOn
)编辑:
添加了一个显示最小工作示例的存储库,该示例将clj文件放入资源https://github.com/christoph-frick/try-java-clara
关于java - gradle构建时未生成Clojure(声明规则)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63512470/