【问题标题】:Plugins in a Multiproject fails at Grails 3.2.11多项目中的插件在 Grails 3.2.11 中失败
【发布时间】:2017-07-14 19:22:03
【问题描述】:

配置

按照 Grails 3.2.11 手册中的Plugins and Multi-Project Builds section,假设我可以在终端中使用以下命令设置多项目:

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 执行的:

  • Groovy: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 上运行

提前致谢。

【问题讨论】:

    标签: grails plugins multi-project grails3 grails-3.2


    【解决方案1】:

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

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

    你可以在下一个 GitHub 的提交中看到:https://github.com/esalomon/multi-project-test2/commit/d92c3fbc67156bcd1af9f47dc6f2984534154bad

    以上更新后multi-project-test2可以下载了,就可以正常使用了。

    【讨论】:

      【解决方案2】:

      此时可能出现问题:

      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 脚本是用来演示的,因为显然之前不够清楚

      【讨论】:

      • 恐怕我没有听懂你想说的话。为澄清起见,您可以打开 myapp/build.gradle 并添加闭包定义来配置插件,而不是使用 echo "grails { plugins { compile project(':myplugin') } }" &gt;&gt; myapp/build.gradle 命令。
      • 对,但我试图指导您使用 ed 自动化该部分,因为它对您没有意义,我已经更新了答案,这正是您需要做的 - 显然改变:htmlunit:2.18" 所有这些,甚至是与您希望添加条目的行匹配的实际行,以在 a 之后的行上添加额外空格以匹配您的文件等
      • 闭包已经存在,因此您要附加现有闭包而不是添加新块,文档是否说明您应该添加一个全新的闭包,或者当您添加新插件时,您是否会创建一个新的闭包每个插件或者你附加现有的块你还没有看到你出错的地方吗?
      • 好的,首先,非常感谢您的回复。其次,我对此进行了更多研究,现在我对您在说什么有了更多的了解。但是,似乎此响应没有回答问题。事情是这样的,echo 命令正在为插件参考创建一个 grails 部分,这根据 grails 文档是有效的。正如您所说,文件中已经有一个依赖项部分。如果将依赖项放在那里会有所不同,尽管如此,我已经尝试将插件引用放在那里,但它不起作用。
      猜你喜欢
      • 2011-05-22
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 2018-06-28
      相关资源
      最近更新 更多