grails - 使用内联插件运行 Grails 3 项目

标签 grails gradle groovy grails-plugin grails-3.0

我几乎可以肯定这是一个愚蠢的问题,但我不知道答案:)我正在将我的项目从 Grails 2.5 升级到 3,并试图掌握新版本内联插件结构,旧方法工作正常,但很难让新方法工作。

我的目录结构如下:


    /
    /settings.gradle
    /myApp             #contains a grails 3 application
    /myPlugin1         #contains a grails 3 plugin
    /myPlugin2         #contains a grails 3 plugin

/settings.gradle 包含:


    include 'myPlugin1', 'myPlugin2'
    project(':myPlugin1').projectDir = new File('myPlugin1')
    project(':myPlugin2').projectDir = new File('myPlugin2')

我的/myApp 中的 build.gradle 包含:


    compile project(":myPlugin1"), project(":myPlugin2")

据我所知,上述内容是正确的,因为当我从根目录运行“gradle build”时,它会成功构建插件。然而,当我运行时


    grails run-app

从 myApp 目录中,我收到以下错误:


    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)

所以问题确实是 - 如何让我的应用程序在正确的位置查找内联插件?我尝试在 myApp 中创建一个 settings.gradle ,但收到如下其他错误:


    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.

提前致谢。

最佳答案

上下文

我在 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 使用以下内容创建多项目的 settings.gradle 文件:

include 'myApp', 'myPlugin1', 'myPlugin2'
project(':myApp').name = 'myApp'

5 myApp 的 build.gradle 文件已使用内联插件引用进行更新:

grails {
    plugins {
        compile project(":myPlugin1")
        compile project(":myPlugin2")
    }
}

项目测试

创建三个 Controller ,每个 Grails 项目一个,以便测试应用程序:

1 myApp 的 Controller 已创建:

cd myApp
grails create-controller myAppController

2 myApp 的 Controller 使用以下代码更新:

package myapp

class AppController {

    def index() {
        render "[${new Date()}] This is the myApp's appController's index response."
    }
}

3 myPlugin1 的 Controller 已创建:

cd myPlugin1
grails create-controller myPlugin1Controller

4 myPlugin1 的 Controller 使用以下代码更新:

package myplugin1

class Plugin1Controller {

    def index() {
        render "[${new Date()}] This is the myPlugin1's plugin1Controller's index response."
    }
}

5 myPlugin2 的 Controller 已创建:

cd myPlugin2
grails create-controller myPlugin2Controller

6 myPlugin2 的 Controller 使用以下代码更新:

打包myplugin2

class Plugin2Controller {

    def index() {
        render "[${new Date()}] This is the myPlugin2's plugin2Controller's index response."
    }
}

项目执行

当使用 run-app 命令执行 myApp 项目时,它会显示带有三个 Controller 的 Grails 主页面,每个 Controller 来自每个 Grails 项目:

cd myApp
grails run-app
| Running application...
Grails application running at http://localhost:8080 in environment: development

结论

我希望这可以帮助其他人,问候。

关于grails - 使用内联插件运行 Grails 3 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34470356/

相关文章:

chalice 2.0 : Use variable for image resource

kotlin - 元数据相关性的生成类(带有kapt)

java - 如何计算文件的 SHA512?

java - 查找 50 个最便宜的不匹配价格

grails - 使用Grails网站网格main.gsp在我的表单上无法使用Bootstrap日期选择器-但适用于独立表单

forms - Grails表单选择选项

java - 从 github 克隆现有 Android 项目时出错

安卓测试 : 'Multiple dex files' when using 'gradle check connectedCheck'

Groovy GString 和数字格式

spring-mvc - 普通Spring MVC中的GSP-AST转换不适用于taglib