繁体   English   中英

gradle 构建时未生成 Clojure(克拉拉规则)文件

[英]Clojure (clara rule) file not generated when gradle build

我有一个 Spring 应用程序,它集成了从 java class 触发的 clara 规则引擎 (clojure) 文件。 使用 gradle 构建应用程序时,不会生成 clojure 文件作为 JAR 的一部分。

因此,在运行 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")
    }
}

Putting the Clojure files (the Clara rules) in a place, where they end up in the correct place inside the JAR, would make the copy task obsolute (which is not used for building the JAR -- at least from the part of the build.gradle我们可以在问题中看到。

  1. 将文件从src/main/resources/au.com.acme.mti.mec.runtime.rulessrc/main/resources/au/com/acme/mti/mec/runtime/rules
  2. 摆脱copyRules任务(它是dependsOn

编辑:

添加了一个显示最小工作示例的存储库,它将 clj 文件放入资源https://github.com/christoph-frick/try-java-clara

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM