java - 调用 Clojure 代码时无法编译 Java 类

标签 java clojure build.gradle gradle-plugin

将 clojure 添加到现有的 gradle java 项目

我有一个Java我想开始尝试添加一些项目 Clojure到,但我遇到了一些问题。我正在使用IntelliJ IDEA草书 Clojure IntelliJ 插件。

我也在使用gradle-clojure Clojure 的插件。我的 Java 类可以识别并调用我的 Clojure代码,但是我的Java代码将不再编译,因为在编译时它无法再看到我的 Clojure代码。

我需要在我的 build.gradle 中添加额外的步骤吗? ?我需要编译我的 Clojure在尝试编译之前分开并手动Java

任何帮助将不胜感激。

环境

gradle-clojure v0.3.1
gradle v4.4.1Java v1.8
MacOS High Sierra 上的 Intellij IDE

Stacktrace <> Task :compileJava FAILED java:8: error: cannot find symbol import com.example.clojure;

最佳答案

您可以使用 Netflix 的 Clojure Wrapper,nebula.clojure

以下是使用 Java 和 Clojure 的项目的 Gradle Build 脚本示例:

buildscript {
    ext {
        springBootVersion = '1.5.8.RELEASE'
    }
    repositories {
        jcenter()
        maven { url 'http://clojars.org/repo' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "com.netflix.nebula:nebula-clojure-plugin:4.4.0"
    }
}


plugins {
    id "nebula.clojure" version "4.4.0"
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


group 'com.demo'
def artifactName = 'demo-service'
version = latestRepoTag()


static def latestRepoTag() {
    def cmd = "git describe --abbrev=0"
    def proc = cmd.execute();
    return proc.text.trim();
}

sourceCompatibility = 1.8
targetCompatibility = 1.8


ext['spring-restdocs.version'] = '1.2.1.RELEASE'
ext {
    springCloudVersion = 'Dalston.SR4'
}

compileJava {
    classpath = project.files(
            project.compileClojure.outputs,
            classpath
    )
}

compileClojure {
    jvmOptions {
        jvmArgs '-Djava.awt.headless=true'
    }
}

repositories {
    jcenter()
    maven { url 'http://clojars.org/repo' }
}

jar {
    baseName = "${artifactName}"
    version = latestRepoTag()
}


clojure.aotCompile = true

configurations{
    dev
}


dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR3'
    }
}


dependencies {

    compile 'org.clojure:clojure:1.6.0'

    compile('com.google.guava:guava:19.0')
    compile("commons-io:commons-io:2.5")
    compile "org.apache.pdfbox:pdfbox:2.0.0-RC3"
    compile("org.apache.commons:commons-lang3:3.0")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-jdbc")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.cloud:spring-cloud-starter-eureka")

    compileOnly("org.projectlombok:lombok:1.16.6")

    runtime('com.h2database:h2:1.4.190')
    runtime("com.ingres.jdbc:iijdbc:10.0-4.0.5")
    runtime('org.apache.commons:commons-dbcp2:2.1.1')
    runtime('org.postgresql:postgresql:9.4.1209')

    dev("org.springframework.boot:spring-boot-devtools")

    testCompile('com.jayway.jsonpath:json-path')
    testCompile('com.jayway.jsonpath:json-path-assert:2.2.0')
    testCompile('com.google.code.gson:gson:2.8.1')
    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.springframework.restdocs:spring-restdocs-mockmvc:1.2.1.RELEASE")

}

task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
}

bootRun {
    classpath = sourceSets.main.runtimeClasspath + configurations.dev
    systemProperties = System.properties
    jvmArgs = ["-client", "-Dsun.net.inetaddr.ttl=60", "-Djava.security.egd=file:/dev/./urandom"]
    environment = [
            'spring_profiles_active': 'beta,fast_discovery'
    ]
}

这是一个link到 Gradle 插件文档站点上的插件:

关于java - 调用 Clojure 代码时无法编译 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48212314/

相关文章:

java - 如何在不使用cookie的情况下在spring Controller 中获取客户端时区偏移量?

java - ;在条件结束时导致意外行为

java - 从音频 PCM 16 位到 8 位 - 有噪音

java - Android Studio 3.5.3 为项目生成一些损坏的 java 类

android - 错误 :Newer :Execution failed for task ':app:dexDebug' . com.android.ide.common.process.ProcessException

java - 在现有元素之后添加新元素到 LinkedList 时的性能

rest - 从 Spring Boot RestController 返回 Clojure PersistentVector

Clojure:删除树的所有叶子中的值

clojure - (= [ :a :b] (list :a :b)) returns true in clojure?

安卓工作室 : Error in 'getDefaultdProguarFile()'