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 compileMy question is then, How do I set up t开发者_Go百科he 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.
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)
精彩评论