0

配置

按照 Grails 3.2.11 手册中的插件和多项目构建部分,假设我可以在终端中使用以下命令设置多项目:

echo "Creating the root folder..."
mkdir test-multi-project
cd test-multi-project

echo "Creating the settings.gradle file..."
echo "include 'myapp', 'myplugin'" >> settings.gradle

echo "Creating the Grails application..."
grails create-app myapp

echo "Creating the Grails plugin..."
grails create-plugin myplugin

echo "Configuring the dependency between the application and the plugin..."
echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle 

echo "Executing the Grails application..."
cd myapp
grails run-app 

错误

但是,当我尝试使用这些命令来创建和配置 Grails 应用程序和插件时,该grails run-app命令会引发下一个错误:

FAILURE: Build failed with an exception.

* Where:
Build file '~/test-multi-project/myapp/build.gradle' line: 61

* What went wrong:
A problem occurred evaluating root project 'myapp'.
> Project with path ':myplugin' 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.

CONFIGURE FAILED

Total time: 4.835 secs
| Error Error initializing classpath: Project with path ':myplugin' could not be found in root project 'myapp'. (Use --stacktrace to see the full trace)

附加信息

我已经使用 Grails 3.2.8、3.2.9、3.2.10 和 3.2.11 测试了上述命令,并且代码抛出了相同的错误。

另一方面,我使用 Grails 3.2.3、3.2.5 和 3.2.7 测试了上述命令,项目执行良好。此外,Grails 登录页面显示应用程序正在使用“mypluin”。

注意,我使用 sdk 来处理 Grails 版本。这些命令是使用 Java 1.7 和 Yosemite 执行的:

  • 时髦的:2.4.7
  • Ant:2015 年 6 月 29 日编译的 Apache Ant(TM) 版本 1.9.6
  • JVM:1.7.0_141(Azul Systems, Inc. 24.141-b11)
  • 操作系统:Mac OS X 10.10.5 x86_64

问题:

我想知道我还需要做什么或者我做错了什么才能使此代码在 Grails 3.2.11 上运行

提前致谢。

4

2 回答 2

1

multi-project-test2/myapp/settings.gradleJeff Brown 修复了删除文件并将下一行添加到文件中的上述问题multi-project-test2/settings.gradle

project(':myapp').name = 'myapp'

正如您在下一个 GitHub 提交中看到的那样:https ://github.com/esalomon/multi-project-test2/commit/d92c3fbc67156bcd1af9f47dc6f2984534154bad

上述更新后,可以下载multi-project-test2并且可以正常工作。

于 2017-09-26T16:38:49.357 回答
0

在这一点上很可能出错了:

echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle 

该段需要添加到该文件的现有块而不是新块(不是我测试过的)

当您手动执行这些步骤时会发生什么?它是否以这种方式工作,如果是这样,您是否考虑过对更改的文件进行差异以查看有什么不同。

您提供的脚本很棒,也许其他人希望通过它运行,但我怀疑这是已经指出的。

您应该查看ed类似以下示例的内容:

我正在使用一个 grails 3.2.8 应用程序,它在依赖项段中的结尾如下所示:

   runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

现在如果我执行

test328$ ed -s build.gradle <<EOF >/dev/null
g/^    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
a
compile project(':myplugin') 
.
w
q
EOF

你现在可以看到:

tail -n20 build.gradle 
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
compile project(':myplugin') 
}

添加的新条目。您将需要在 grails 生成的现有文件中找到一个指针,并像上面一样使用该指针来添加您的条目

ed 脚本用于演示这个,因为显然之前不够清楚

于 2017-07-14T21:23:42.007 回答