如何使用 Gradle 设置多项目 Grails?

发布于 2024-11-19 01:18:52 字数 893 浏览 2 评论 0原文

我正在尝试为多项目 Grails 应用程序设置一个 gradle 构建脚本。 我已经使用了 grails-gradle 插件 并启动并运行它来创建一个新应用程序。

但是,当我想将现有的 Grails 多项目应用程序转换为使用 gradle 时,我遇到了一些问题。

我已在 settings.gradle 文件中声明了所有子项目,如下所示:

include 'core',

        //Plugins
        'plugin1',
        'plugin2'

并为每个子项目在其自己的 build.gradle 文件中设置其依赖项。例如 plugin1 依赖于plugin2,因此我在plugin1 的build.gradle 文件中声明了以下内容:

dependencies {
  compile project(':plugin2')
}

但是,当我尝试运行gradle test 命令时,出现以下错误:

未解决的依赖关系

出了什么问题:
任务“:plugin1:test”执行失败。
原因:无法解析配置“:plugin1:runtime”的所有依赖项:
- 未解决的依赖项:{}#plugin2;1.5-SNAPSHOT:在 {}#plugin2;1.5-SNAPSHOT 中找不到配置:“默认”。它是 {}#plugin1;1.5-SNAPSHOT 编译所需的。

我的问题是,如何在 gradle 中设置子项目依赖项?

我已在每个子项目 BuildConfig.groovy 中将它们声明为内联依赖项,我是否也必须在 gradle 中声明它们?

I am trying to set up a gradle build script for a multiproject grails application.
I have used the grails-gradle plugin and got it up and running to create a new application.

However, I have some problems when I want to convert an existing grails multiproject application to use gradle.

I have declared all subprojects in my settings.gradle file as follows:

include 'core',

        //Plugins
        'plugin1',
        'plugin2'

and for each subproject set up its dependencies in their own build.gradle files. e.g.
plugin1 is dependent on plugin2 so I have declared the following in plugin1's build.gradle file:

dependencies {
  compile project(':plugin2')
}

However, I got the following error when I try to run the gradle test command:

UNRESOLVED DEPENDENCIES

What went wrong:
Execution failed for task ':plugin1:test'.
Cause: Could not resolve all dependencies for configuration ':plugin1:runtime':
- unresolved dependency: {}#plugin2;1.5-SNAPSHOT: configuration not found in {}#plugin2;1.5-SNAPSHOT: 'default'. It was required from {}#plugin1;1.5-SNAPSHOT compile

My question is then, How do I set up the subproject dependencies in gradle?

I have declared them in each subprojects BuildConfig.groovy as inline dependencies, do I have to declare them in gradle as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姜生凉生 2024-11-26 01:18:52

如果其他人也有同样的问题,我回答我自己的问题。

我想设置多项目 Grails 应用程序的构建顺序(一个依赖于位于单独文件夹中的多个 grails 插件的主应用程序)。

我最终在每个子项目构建文件中声明了一个 dependsOn()

示例:
我的主要应用程序依赖于pluginA和pluginB。 PluginB 依赖于 PluginC

在我的根 build.gradle 中,我声明:

dependsOnChildren()

在我的根 settings.gradle 中,我声明:

include "pluginA","pluginB","pluginC"

在pluginB:s build.gradle 文件中,我声明

dependsOn(":pluginC")

解决了我的问题。然而,它也引入了另一个问题,即每个插件的测试已编译但未执行。

我找到了一个解决方案 @ GRAILS-7296

我创建了一个 _Events.groovy 文件位于每个子项目的 scripts 文件夹中,并包含:

// Override to workaround GRAILS-7296
org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport.metaClass.getSourceDir = { ->
    new File(delegate.buildBinding.grailsSettings.testSourceDir, delegate.relativeSourcePath)
}

这解决了我的所有问题,我现在有了一个使用 Gradle 进行构建的多项目 grails 应用程序。

I answer my own question If anyone else have the same issue.

I wanted to set the build order for a multiproject grails application (A main application that was dependent on several grails-plugins located in separate folders).

I ended up by declaring a dependsOn() in each subproject buildfile.

Example:
My main application is dependent on pluginA and pluginB. PluginB is dependent on PluginC

In my root build.gradle I declared:

dependsOnChildren()

and in my root settings.gradle I declared:

include "pluginA","pluginB","pluginC"

In pluginB:s build.gradle file I declared

dependsOn(":pluginC")

That solved my issue. However it also introduced another issue that the the tests for each plugin were compiled but not executed.

I found a solution for this @ GRAILS-7296

I created a _Events.groovy file in the scripts folder for each subproject and included:

// Override to workaround GRAILS-7296
org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport.metaClass.getSourceDir = { ->
    new File(delegate.buildBinding.grailsSettings.testSourceDir, delegate.relativeSourcePath)
}

This solved all my problems and I have now a multiproject-grails application that uses Gradle for the build.

夏末的微笑 2024-11-26 01:18:52

事实证明,grails-gradle-plugin并没有应用groovyjava插件,只添加了一些通常由java插件添加的配置,即编译运行时测试。因此,没有通常在跨项目依赖项中使用的默认配置,也没有存储项目生成的工件的存档配置。

所以看来这个插件目前不支持这样的配置。另请注意,通常 Grails 插件依赖项也不在 build.gradle 中处理。我认为我们可以尝试修复它,但我意识到我并不完全理解您的用例。

我相信你现在想要完成的事情相当于

grails.plugin.location.'plugin-tws-communication' = "../plugin-tws-communication"

在主项目中编写BuildConfig.groovy,但是从Grails的角度来看,插件之间的关系是什么?是:

  • 安装依赖项(如插件定义中的 dependsOn 映射)
  • 构建顺序依赖项(因此一个插件必须在另一个插件之前构建?然后我们可以通过任务 dependsOn 来完成它>)
  • 编译依赖项(因此一个插件需要另一个插件的类才能编译)

It turns out that grails-gradle-plugin doesn't apply groovy or java plugins, only adds some of the configurations normally added by java plugin, namely compile, runtime and test. So there is no default configuration that is normally used in cross-project dependencies, nor archive configuration that stores artifacts produced by the project.

So it seems that such configuration is not supported by this plugin at the moment. Please also note that generally Grails plugin dependencies are not handled in build.gradle either. I think that we can try to fix it, but I realized that I don't fully understand your use case.

I believe that what you want to accomplish now is something equivalent to writing

grails.plugin.location.'plugin-tws-communication' = "../plugin-tws-communication"

in BuildConfig.groovy for the main project, but what's the relation between the plugins from Grails perspective? Is it:

  • installation dependency (as in dependsOn map in plugin definition)
  • build order dependency (so one plugin must be built before the other one? Then we can accomplish it with tasks dependsOn)
  • compile dependency (so one plugin needs classes from the other to compile)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文