如何使用Gradle设置多项目Grails? [英] How to set up a multiproject Grails using Gradle?

查看:150
本文介绍了如何使用Gradle设置多项目Grails?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

然而,当我想要将现有的grails多项目应用程序转换为gradle时,我遇到了一些问题。



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

 
包含'core',

//插件
'plugin1',
'plugin2'

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

 
依赖关系{
编译项目(':plugin2')
}

然而,当我尝试运行 gradle test

命令:

未解决的相关性



出错:
$

原因:无法解析配置':plugin1:runtime'的所有依赖项: -
- 未解析的依赖项:
执行失败的任务':plugin1:test' {}#plugin2; 1.5-SNAPSHOT:{}#plugin2中未找到配置; 1.5-SNAPSHOT:'default'。从{}#plugin1; 1.5-SNAPSHOT编译是必需的



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



我已经在每个子项目 BuildConfig.groovy 中将它们声明为内联依赖关系,是否也必须在gradle中声明它们?
<解决方案我回答我自己的问题如果其他人有同样的问题。

我想设置构建订购一个多项目grails应用程序(一个主要的应用程序依赖于位于不同文件夹中的几个grails插件)。

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



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



在我的根目录 build.gradle 中声明:

  dependsOnChildren()

我的根 settings.gradle 我声明:

  includepluginA, pluginB,pluginC

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

  dependsOn(:pluginC)

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



我发现了这个@ GRAILS-7296



我创建了一个 _Events .groovy 文件放在每个子项目的 scripts 文件夹中,包括:

  //覆盖解决方法GRAILS-7296 
org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport.metaClass.getSourceDir = { - >
新文件(delegate.buildBinding.grailsS​​ettings.testSourceDir,delegate.relativeSourcePath)
}

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


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?

解决方案

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.

这篇关于如何使用Gradle设置多项目Grails?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆