简体   繁体   English

如何在Intellij Idea中使用Gradle向具有相同级别的模块正确添加依赖项?

[英]How to properly add a dependency to a module that's on the same level using Gradle in Intellij Idea?

I have a plain Java EE project that I am porting over to Gradle. 我有一个普通的Java EE项目,正在移植到Gradle。 The structure I have created in Intellij Idea consists of these sub-projects: 我在Intellij Idea中创建的结构包括以下子项目:

\ee_forum_gradle (Uses ear plugin and deploys both the ejb and web project)
\ee_forum_gradle_ejb
\ee_forum_gradle_web (Uses war plugin and is dependent on the ejb project)

My problem is that the web project depends on the ejb project and I have to click add dependency on module 'ee_forum_gradle_ejb_main' in the web project every time I open it up in Intellij, because every time gradle is running the imports, this setting gets lost. 我的问题是该Web项目依赖于ejb项目,每次在Intellij中打开该项目时,都必须在该Web项目中单击对模块ee_forum_gradle_ejb_main的添加依赖项,因为每次gradle运行导入时,此设置都会丢失。

I tried to import the ejb project into the web project using gradle. 我试图使用gradle将ejb项目导入到Web项目中。 So I added 所以我加了

includeFlat 'ee_forum_gradle_ejb'

to the settings.gradle of the web project and 到Web项目的settings.gradle并

compile project(':ee_forum_gradle_ejb')

to the build.gradle file of the web project. 到Web项目的build.gradle文件。 If I then try to run it on my Wildfly 10 server I get the following error: 如果然后尝试在Wildfly 10服务器上运行它,则会出现以下错误:

"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".deploymentCompleteService","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".beanmanager","jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\""],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_ejb-1.0-SNAPSHOT.jar\".component.PostBean.START is missing [jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\"]","jboss.deployment.unit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".WeldStartService is missing [jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\"]","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".batch.environment is missing [jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".beanmanager]","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".weld.weldClassIntrospector is missing [jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".beanmanager]","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_ejb-1.0-SNAPSHOT.jar\".component.UserBean.START is missing [jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\"]","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_ejb-1.0-SNAPSHOT.jar\".component.ThreadBean.START is missing [jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\"]","jboss.deployment.unit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".deploymentCompleteService is missing [jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_web-1.0-SNAPSHOT.war\".deploymentCompleteService]","jboss.deployment.subunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear\".\"ee_forum_gradle_ejb-1.0-SNAPSHOT.jar\".component.BoardBean.START is missing [jboss.persistenceunit.\"ee_forum_gradle-1.0-SNAPSHOT.ear/ee_forum_gradle_web-1.0-SNAPSHOT.war#forum-jpa\"]"]}

Any ideas on how to get this Gradle project running are much appreciated. 非常感谢有关如何使该Gradle项目运行的任何想法。 Like I wrote, if I click on add dependency on module.. the project is running successfully but I have to repeat this step every time. 就像我写的一样,如果我单击“ 添加模块依赖项”,则该项目成功运行,但是每次都必须重复此步骤。

Ok so the solution is to use 好了,解决方案是使用

include('ee_forum_gradle_ejb')

in the settings.gradle file of the web project and then 在Web项目的settings.gradle文件中,然后

providedCompile project(':ee_forum_gradle_ejb')

in the build.gradle file of the web project. 在Web项目的build.gradle文件中。

I think the problem with just using compile, instead of providedCompile, is that the ejb project is included twice and that's confusing the server somehow. 我认为仅使用compile而不是provideCompile的问题在于,两次包含了ejb项目,这使服务器有些混乱。

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

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