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

2024-01-09

我几乎可以肯定这是一个愚蠢的问题,但我不知道答案:)我正在将我的项目从 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.

  

提前致谢。


Context

我在 github 上创建了一个多项目测试,以提供一个可行的解决方案。此多项目测试是使用 Grails 3.2.11 和 Java 1.7 创建的。你可以在这里下载:https://github.com/esalomon/multi-project-test3 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")
    }
}

项目测试

创建三个控制器,每个 Grails 项目中都有一个,以便测试应用程序:

1 myApp 的控制器已创建:

cd myApp
grails create-controller myAppController

2 myApp 的控制器使用以下代码更新:

package myapp

class AppController {

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

3 myPlugin1 的控制器已创建:

cd myPlugin1
grails create-controller myPlugin1Controller

4 myPlugin1 的控制器使用以下代码更新:

package myplugin1

class Plugin1Controller {

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

5 myPlugin2 的控制器已创建:

cd myPlugin2
grails create-controller myPlugin2Controller

6 myPlugin2 的控制器使用以下代码更新:

包 myplugin2

class Plugin2Controller {

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

项目执行

当使用 run-app 命令执行 myApp 项目时,它会显示包含三个控制器的 Grails 主页面,每个控制器来自每个 Grails 项目:

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

结论

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用内联插件运行 Grails 3 项目 的相关文章

随机推荐