在线插件中运行Grails 3项目 [英] Running a Grails 3 project with in line plugins
问题描述
我几乎可以肯定这是一个愚蠢的问题,但我不知道答案:)我正在将我的项目从Grails 2.5升级到3,并试图掌握新的内联插件结构,旧的方式工作正常,但努力获得新的工作方式。
我有一个目录结构如下:
/
/settings.gradle
/ myApp#包含一个grails 3应用程序
/ myPlugin1#包含一个grails 3插件
/ myPlugin2#包含一个Grails 3插件
包括'myPlugin1','myPlugin2'
project(':myPlugin1')。projectDir = new File('myPlugin1')
project(':myPlugin2')。projectDir = new File('myPlugin2')
我的构建。 gradle in / myApp包含:
编译项目ct(:myPlugin1),project(:myPlugin2)
以上,据我所知是正确的,因为当我从根节点运行'gradle build'时,它成功地构建了插件。然而,当我运行
grails run-app
在myApp目录中,我收到以下错误:
FAILURE:Build例外失败。
*其中:
构建文件'/Users/donald/myApp/build.gradle'行:76
*出错:
A问题发生在评估根项目'myApp'。
>无法在根项目'myApp'中找到包含路径''myPlugin1'的项目。
*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。
构建失败
总时间:1.572秒
|错误初始化类路径时出错:在根项目myApp中找不到具有路径':myPlugin1'的项目。 (使用--stacktrace查看完整跟踪)
所以问题是真的 - 我如何让我的应用程序在正确的地方寻找我的内联插件?我已经尝试在myApp中创建一个settings.gradle,并且我得到了类似这样的其他错误:
插件'io.spring。依赖关系管理已经在脚本类路径中。脚本类路径上的插件无法应用于插件{}块中。将apply plugin:'io.spring.dependency-management'添加到脚本的主体以使用该插件。
预先致谢。
Context
我在github上创建了一个多项目测试,以提供一个可行的解决方案。这个多项目测试是使用Grails 3.2.11和Java 1.7创建的。你可以从这里下载: https://github.com/esalomon/multi-project-test3
接下来您会找到创建说明。
创建项目
1创建多项目文件夹:
mkdir multi-project-test3
cd multi-project-test3
<2>创建Grails应用程序和插件:
grails create-app myApp
grails create-plugin myPlugin1
grails create-plugin myPlugin2
<3> myApp的settings.gradle文件被删除:
rm myApp / settings.gradle
4多项目设置.gradle文件是用下一个内容创建的:
包括'myApp','myPlugin1','myPlugin2'
项目(':myApp')。name ='myApp
5 myApp的build.gradle文件使用内嵌插件引用进行更新:
grails {
plugins {
compile project(:myPlugin1)
compile project(:myPlugin2)
$ b 项目测试
创建三个控制器,每个Grails项目中有一个控制器用于测试应用程序:
1创建myApp控制器:
cd myApp
grails create-controller myAppController
2 myApp的控制器更新为下一个代码:
package myapp
class AppController {
def index(){
render[$ {new Date()}]这是myApp的appController的索引响应。
<3> myPlugin1的控制器被创建: cd myPlugin1
grails create-controller myPlugin1Controller
4 myPlugin1的控制器更新为下一个代码:
package myplugin1
class Plugin1Controller {
def index(){
render[$ {new Date()}]这是myPlugin1的plugin1Controller的索引响应。
$ b 5创建myPlugin2的控制器:
cd myPlugin2
grails create-controller myPlugin2Controller
6 myPlugin2的控制器更新为下一个代码:
package myplugin2
class Plugin2Controller {
def index(){
render[$ {new Date()}]这是myPlugin2的plugin2Controller的索引响应。
$ b $ h $>项目执行
使用run-app命令执行myApp项目时,它显示带有三个控制器的主Grails页面,每个Grails项目都有一个:
cd myApp
grails run-app
|正在运行的应用程序...
环境中的http:// localhost:8080运行的Grails应用程序:development
结论
我希望这可以帮助其他人,问候。
I'm almost certain this is a stupid question but I do not know the answer to it :) I'm in the process of upgrading a project of mine from Grails 2.5 to 3 and trying to get to grips with the new inline plugin structure, the old way was working fine but struggling to get the new way working.
I have a directory structure as follows:
/
/settings.gradle
/myApp #contains a grails 3 application
/myPlugin1 #contains a grails 3 plugin
/myPlugin2 #contains a grails 3 plugin
/settings.gradle contains:
include 'myPlugin1', 'myPlugin2'
project(':myPlugin1').projectDir = new File('myPlugin1')
project(':myPlugin2').projectDir = new File('myPlugin2')
My build.gradle in /myApp contains:
compile project(":myPlugin1"), project(":myPlugin2")
The above, as far as I can tell is correct, because when I run 'gradle build' from the root it builds the plugins successfully. However, when I run
grails run-app
From the myApp directory I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/donald/myApp/build.gradle' line: 76
* What went wrong:
A problem occurred evaluating root project 'myApp'.
> Project with path ':myPlugin1' could not be found in root project 'myApp'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.572 secs
| Error Error initializing classpath: Project with path ':myPlugin1' could not be found in root project 'myApp'. (Use --stacktrace to see the full trace)
So the question is really - how do I get my application to look in the right place for my inline plugins? I have tried creating a settings.gradle inside myApp and I get other errors like this:
Plugin 'io.spring.dependency-management' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add "apply plugin: 'io.spring.dependency-management'" to the body of the script to use the plugin.
Thanks in advance.
解决方案 Context
I created a multi-project test at github in order to provide a working solution. This multi-project test was created using Grails 3.2.11 and Java 1.7. You can download it from here: https://github.com/esalomon/multi-project-test3
Next you will find the instructions for its creation.
Projects creation
1 The multi-project folder is created:
mkdir multi-project-test3
cd multi-project-test3
2 The Grails Application and the plugins are created:
grails create-app myApp
grails create-plugin myPlugin1
grails create-plugin myPlugin2
3 The myApp's settings.gradle file is deleted:
rm myApp/settings.gradle
4 The multi-project's settings.gradle file is created with the next contents:
include 'myApp', 'myPlugin1', 'myPlugin2'
project(':myApp').name = 'myApp'
5 The myApp's build.gradle file is updated with the inline plugin references:
grails {
plugins {
compile project(":myPlugin1")
compile project(":myPlugin2")
}
}
Project test
Three controllers are created, one in each Grails project in order to test the application:
1 The myApp's controller is created:
cd myApp
grails create-controller myAppController
2 The myApp's controller is updated with the next code:
package myapp
class AppController {
def index() {
render "[${new Date()}] This is the myApp's appController's index response."
}
}
3 The myPlugin1's controller is created:
cd myPlugin1
grails create-controller myPlugin1Controller
4 The myPlugin1's controller is updated with the next code:
package myplugin1
class Plugin1Controller {
def index() {
render "[${new Date()}] This is the myPlugin1's plugin1Controller's index response."
}
}
5 The myPlugin2's controller is created:
cd myPlugin2
grails create-controller myPlugin2Controller
6 The myPlugin2's controller is updated with the next code:
package myplugin2
class Plugin2Controller {
def index() {
render "[${new Date()}] This is the myPlugin2's plugin2Controller's index response."
}
}
Project execution
When the myApp project is executed with the run-app command, it displays the main Grails page with the three controllers, one from each Grails project:
cd myApp
grails run-app
| Running application...
Grails application running at http://localhost:8080 in environment: development
Conclusion
I hope this can help others, regards.
这篇关于在线插件中运行Grails 3项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!