可以在Gradle中混合.java和.clojure和.scala文件 [英] Can In Gradle mix .java and .clojure and .scala files
问题描述
可以在Gradle中混合.java和.clojure和.scala文件。我想混合几种编程语言,只是在寻找最佳方法。
Can In Gradle mix .java and .clojure and .scala files. I want to mix few programming languages, just searching best way to do it.
推荐答案
我从一个混合项目开始java,scala和clojure。
为了包含scala,我仅添加了 scala插件
I'm starting with a project with mixed java, scala and clojure. In order to include scala I simply added the scala plugin
应用插件: scala
scala依赖项到依赖项部分:
and the scala dependency to dependencies section:
编译'org.scala-lang:scala-library:2.11.7'
要包含clojure,我遵循了此答案。
To include clojure I followed this answer.
我的最终 build.gradle
文件如下所示:
My final build.gradle
file looks like this:
buildscript {
repositories {
maven { url "http://clojars.org/repo" }
mavenCentral()
jcenter()
}
dependencies {
classpath 'clojuresque:clojuresque:1.7.0'
}
}
apply plugin: 'application'
apply plugin: 'scala'
apply plugin: 'clojure'
repositories {
mavenCentral()
maven { url "http://clojars.org/repo" }
}
dependencies {
compile 'org.clojure:clojure:1.7.0'
compile 'org.scala-lang:scala-library:2.11.7'
}
// NOTE: You *must* enable AOT (Ahead-of-Time) compilation in order to use a Clojure class as the main class
clojure.aotCompile = true
clojure.warnOnReflection = true
mainClassName = "foo"
我的项目结构是这样的:
My project structure is this one:
.
├── build.gradle
└── src
└── main
├── clojure
│ └── foo.clj
├── java
│ └── JavaClass.java
└── scala
└── HelloWorld.scala
,然后运行 gradle build
之后,我得到了这个构建文件夹:
and after run gradle build
I'm getting this build folder:
build
├── classes
│ └── main
│ ├── HelloWorld$.class
│ ├── HelloWorld.class
│ ├── JavaClass.class
│ ├── foo$_main.class
│ ├── foo$fn__64.class
│ ├── foo$loading__5340__auto____62.class
│ ├── foo.class
│ └── foo__init.class
├── dependency-cache
├── distributions
│ ├── init-proj-1.0.0.tar
│ └── init-proj-1.0.0.zip
├── libs
│ └── init-proj-1.0.0.jar
├── scripts
│ ├── init-proj
│ └── init-proj.bat
└── tmp
├── compileJava
│ └── emptySourcePathRef
├── compileScala
└── jar
└── MANIFEST.MF
我还没有达到互操作的目的(从scala调用clojure,反之亦然, it在此处进行了讨论),但至少它会生成 .class
文件。
I haven't reach the point of interop (calling clojure from scala and viceversa, it is discussed here), but at least it is generating the .class
files.
这篇关于可以在Gradle中混合.java和.clojure和.scala文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!