Intellij idea Clojure和Groovy集成问题:依赖关系
我正试图在一个Grails3项目上,在Intellij下将一些Clojure代码与Java和Groovy集成。我的最终目标是使用一些Clojure代码与Groovy代码混合 我用Groovy编写了一个类,并试图用Clojure实例化它。我所做的基本上是: 1) 我编写了一个类app/server/src/main/groovy/mypackage/State.groovyIntellij idea Clojure和Groovy集成问题:依赖关系,intellij-idea,grails,groovy,clojure,leiningen,Intellij Idea,Grails,Groovy,Clojure,Leiningen,我正试图在一个Grails3项目上,在Intellij下将一些Clojure代码与Java和Groovy集成。我的最终目标是使用一些Clojure代码与Groovy代码混合 我用Groovy编写了一个类,并试图用Clojure实例化它。我所做的基本上是: 1) 我编写了一个类app/server/src/main/groovy/mypackage/State.groovy package mypackage class State { def Calendar date; def
package mypackage
class State {
def Calendar date;
def static State stateBuilder() {
State state = new State()
state.date = Calendar.getInstance()
return state;
}
2) 然后我编写了名为app/server/src/main/clj/state.clj的文件,如下所示:
(ns mypackage.state)
(import mypackage.State)
(def groovystate (new State))
(println (bean groovystate))
(defn -main
[& args]
(println "Hello, World!"))
3) 最后,我编写了以下app/server/project.clj
(defproject brkmopt "0.1.0-SNAPSHOT"
:description "Test Clojure and Grails integration"
:url ""
:plugins [[lein-localrepo "0.5.4"]]
:license {:name ""
:url ""}
:repositories [["bintray-grails-plugins" "https://dl.bintray.com/grails/plugins"]
["java.net" "https://download.java.net/maven/2"]
]
:dependencies [[org.clojure/clojure "1.9.0"]
[org.codehaus.groovy/groovy-all "3.0.0-alpha-4" :extension "pom"]
[org.grails/grails-datastore-gorm "6.1.9.RELEASE"]
]
:main mypackage.state
:source-paths ["src/main/clj"]
:java-source-paths ["src/main/java"]
:test-paths ["src/test/clj"]
:resource-paths ["resources"]
:target-path "out/production"
:aot :all)
注意,我将:目标路径配置为“out/production”,并将:dependencies配置为下载一些在Groovy项目中lein找不到的依赖项
成功了。运行“lein run”我得到:
正如所料
但如果我替换:
(def groovystate (new State))
借
编译器开始要求更多的依赖项,我花了几个小时在依赖项地狱中,最终导致我在一条死胡同上要求依赖项,我在任何maven存储库中都找不到
project.clj的最新版本为:
(defproject brkmopt "0.1.0-SNAPSHOT"
:description "Test Clojure and Grails integration"
:url ""
:plugins [[lein-localrepo "0.5.4"]]
:license {:name ""
:url ""}
:repositories [["bintray-grails-plugins" "https://dl.bintray.com/grails/plugins"]
["java.net" "https://download.java.net/maven/2"]
;["central" "https://central.maven.org/maven2/"]
;["sonatype" "https://oss.sonatype.org/content/repositories/releases"]
;["snapshots" "https://blueant.com/archiva/snapshots"]
]
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/data.priority-map "0.0.10"]
[com.google.code.gson/gson "2.7"]
[org.codehaus.groovy/groovy-all "3.0.0-alpha-4" :extension "pom"]
[org.grails/grails-datastore-gorm "6.1.9.RELEASE"]
[org.grails.plugins/events "3.3.2"]
[org.grails/grails-core "3.3.3"]
[org.grails/grails-plugin-domain-class "3.3.3"]
[org.grails/grails-web-databinding "3.3.3"]
[org.grails/grails-gsp "3.3.1"]
]
:main mypackage.state
:source-paths ["src/main/clj"]
:java-source-paths ["src/main/java"]
:test-paths ["src/test/clj"]
:resource-paths ["resources"]
:target-path "out/production"
:aot :all)
我找不到GrailsGSP版本3.3.1。无论如何,我相信这不是一条路要走。它应该使用与Grails相同的库,而不是再次下载它们
所有必需的依赖项都位于.dr/.gradle/文件夹中,但我不知道如何使它们对Clojure可见
请告知
----------编辑1----------
根据Alex的建议,我将提供更多信息。
我将Clojure代码嵌入到Grail3项目中,如下图所示:
当它工作时(第一种情况),我看到:
root@linuxkit-025000000001:~/workspace/brkm_app/server# lein run
Compiling com.nitryx.brkmopt.state
{:date nil}
Hello, World!
root@linuxkit-025000000001:~/workspace/brkm_app/server#
root@linuxkit-025000000001:~/workspace/brkm_app/server# lein run
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in central (https://repo1.maven.org/maven2/)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in clojars (https://repo.clojars.org/)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in bintray-grails-plugins (https://dl.bintray.com/grails/plugins)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in java.net (https://download.java.net/maven/2)
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
root@linuxkit-025000000001:~/workspace/brkm_app/server#
当我更改为(println(bean(groovystate))并包含所有可以包含的依赖项时,我看到:
root@linuxkit-025000000001:~/workspace/brkm_app/server# lein run
Compiling com.nitryx.brkmopt.state
{:date nil}
Hello, World!
root@linuxkit-025000000001:~/workspace/brkm_app/server#
root@linuxkit-025000000001:~/workspace/brkm_app/server# lein run
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in central (https://repo1.maven.org/maven2/)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in clojars (https://repo.clojars.org/)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in bintray-grails-plugins (https://dl.bintray.com/grails/plugins)
Could not find artifact org.grails:grails-gsp:jar:3.3.1 in java.net (https://download.java.net/maven/2)
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
root@linuxkit-025000000001:~/workspace/brkm_app/server#
Grails在Gradle上运行,Lein在Maven上运行,我在docker容器上运行,那里没有.m2文件夹
root@linuxkit-025000000001:~# ls -la
total 20
drwxr-xr-x 1 root root 4096 Feb 16 18:41 .
drwxr-xr-x 1 root root 4096 Feb 12 15:18 ..
drwx------ 2 root root 4096 Feb 16 18:41 .cache
drwxr-xr-x 3 root root 4096 Feb 16 16:23 .lein
drwxr-xr-x 1 root root 4096 Feb 12 15:18 .vscode
drwxr-xr-x 15 root root 480 Feb 13 19:42 workspace
root@linuxkit-025000000001:~# cd workspace
root@linuxkit-025000000001:~/workspace# ls -la
total 36
drwxr-xr-x 15 root root 480 Feb 13 19:42 .
drwxr-xr-x 1 root root 4096 Feb 16 18:41 ..
-rw-r--r-- 1 root root 6148 Feb 13 19:27 .DS_Store
drwxr-xr-x 9 root root 288 Feb 15 14:08 .dr
drwxr-xr-x 18 root root 576 Feb 16 22:08 .git
-rw-r--r-- 1 root root 120 Feb 13 17:42 .gitignore
drwxr-xr-x 13 root root 416 Feb 16 17:09 brkm_app
drwxr-xr-x 4 root root 128 Feb 13 16:53 doc
-rw-r--r-- 1 root root 290 Feb 13 18:56 docker-compose.yml
drwxr-xr-x 9 root root 288 Feb 13 19:27 dockerfiles
-rwxr-xr-x 1 root root 994 Feb 13 17:42 run_container_linux.sh
-rwxr-xr-x 1 root root 949 Feb 15 18:47 run_container_mac.sh
-rwxr-xr-x 1 root root 37 Feb 13 17:50 run_idea.sh
-rwxr-xr-x 1 root root 20 Feb 13 17:49 run_visual_studio_code.sh
drwxr-xr-x 8 root root 256 Feb 15 11:51 tests
root@linuxkit-025000000001:~/workspace# cd brkm_app/
root@linuxkit-025000000001:~/workspace/brkm_app# ls -la
total 40
drwxr-xr-x 13 root root 416 Feb 16 17:09 .
drwxr-xr-x 15 root root 480 Feb 13 19:42 ..
-rw-r--r-- 1 root root 21 Feb 13 16:53 .gitignore
drwxr-xr-x 4 root root 128 Feb 13 17:37 .gradle
drwxr-xr-x 12 root root 384 Feb 16 22:13 .idea
-rw-r--r-- 1 root root 692 Feb 13 17:40 brkm_app.iml
drwxr-xr-x 13 root root 416 Feb 13 16:53 client
drwxr-xr-x 3 root root 96 Feb 13 16:53 gradle
-rwxr-xr-x 1 root root 4971 Feb 13 16:53 gradlew
-rwxr-xr-x 1 root root 2404 Feb 13 16:53 gradlew.bat
-rwxr-xr-x 1 root root 12540 Feb 15 11:51 lein
drwxr-xr-x 16 root root 512 Feb 16 22:08 server
-rw-r--r-- 1 root root 26 Feb 13 16:53 settings.gradle
我在运行find命令的.dr文件夹下找到了依赖项。我真的不明白它们为什么在那里,以及Grails/Gradle是如何使用它们的。Grails web数据绑定版本3.3.3在Maven central repo中,默认情况下Leiningen应该包括它。也许最好包括您看到的输出和一个lis您希望用于grails的libs的t
Leiningen在后台使用Maven工具,并将库缓存在~/.m2/存储库中。我不知道如何让它使用.dr/.gradle/文件夹中的deps。我看到build.gradle和project.clj,但您确实需要选择一个。因为看起来您正在集成到现有的gradle项目中,我建议安装Gradle Clojure插件:。不要按照关于clj工具的说明操作,只要像其他插件一样添加它(如果您以前已经这样做过)
这有望解决您的任何依赖性问题。clojure插件将能够编译您的clojure代码,作为正常Gradle构建过程的一部分。谢谢您的帮助。Grails在Gradle上运行,而不是在Maven上运行。这可能就是依赖性位于.dr文件夹下的原因。我一直是一个Maven人,也是一个Gradle新手。我是这样做的还没有真正理解为什么依赖项在.dr下,以及如何让Clojure找到它们。我编辑了这篇文章以包含更多细节。我期待着得到任何关于这一点的线索。我处于死胡同中。缺少的库是grails gsp而不是grails web数据绑定…我通过编辑修复了这篇文章。无论如何…我不应该手动添加grails de在project.clj上挂起。每次我修复一个会破坏另一个。必须有一种方法从Gradle repository或类似的东西中引用所有Grails依赖项。它不起作用。该插件似乎需要Gradle 5。我的项目使用Gradle 3.4.1附带的Grails 3.3.9。我正在试图找出如何迁移到Gradle 5G3 cCurrently不明确支持Gradle 5:0.4.0的插件与4.x一起工作;如果您能够将Grails项目更新为至少4.2良好的调用!谢谢您。我在上面。对于如何将Gradle升级到4.2有点迷茫。。。