I am working on a multi module grails plugin project. I am planning to use gradle to build the project.
Since, gradle needs a build.gradle under each and every project to specify the dependencies and repositories, is it possible to create a custom gradle plugin project that copies the dependencies and repositories section from buildconfig.groovy into build.gradle at build time.
Buid time, in the sense, if i am doing gradle release in jenkins, it will checkout the project from svn and custom gradle plugin should be executed to generate the build.gradle under each and every project and then the normal flow should happen.
Is that feasible in gradle? In maven, we can inject similar plugins in the build phase or install phase.
Can you please let me know, if it can be done through gradle plugin or is ther any other way of doing things.
Do you want it to actually generate a build.gradle file for the project? or do you just want to pull out common dependencies so that you don’t have to write them over and over again in each project - similar to how Maven works with parent poms?
If it’s the later, you can do this pretty easily by using an apply script and then applying it in each of your project’s build.gradle file.
I did this at my previous company where all our projects were using basic modules of the Spring framework. I used them also to set up the maven repositories and some default tasks (like javadoc, unversioned war files for deployment, etc…)
Apply script hosted in your maven repo, or on an internal intranet somewhere:
Main is the main project which has two grails project A and B. As per grails-gradle plugin, we should not put the dependencies in buildconfig.groovy and we should place them in build.gradle. In order to make the development simple in grails and not to mix up with gradle, I thought modules (A) and (B) can be developed in grails and we can generate the build.gradle under module (A) and module(B)
from the main project [main]. For this to happen, i have to pick the dependencies and repository section from buildConfig.groovy and place it in the generated build.gradle
If so, I don’t see any where saying that you shouldn’t use the buildconfig.groovy file.
However, seems to me that all you really need is to set up your main project to setup project’s A and B. Which you can do from reading the link I posted earlier.
You would have something like this in your main/build.gradle file:
If that is the case, then i have to pick the plugins and dependencies from buildconfig.groovy and place that in build.gradle. I am not sure how to read/ get the dependencies and plugins from buildconfig.groovy to build.gradle. Can you please help me on that.
Based on that presentation, yes the buildconfig.groovy dependencies are switched off. I think the intention there is to actually move away from grails doing that management altogether. I think the recommendation then is to actually take out those plugin dependencies from the buildconfig and put them as normal dependencies in your build.gradle file. Indeed he removes the whole dependency resolution section from the buildconfig altogether.
I imagine it might be rather difficult to actually read the buildconfig file and pull those dependencies out automagically using Gradle. True, that file is using a ConfigSlurper, but I believe there are some special methods that you’d need to somehow mock out.
My suggestion would be to do what he does with the tomcat plugin and just take those plugin dependencies you have in your buildconfig file, and put them manually in your build.gradle file as a ‘org.grails:grails-plugin-[whatever]’ dependency.
I tried using configSluper for buildconfig.groovy, i was able to access other properties defined there. but for dependencies it shows the value 'dependency:[resolution:script13733932805231614944274$_run_closure1@71dc48dd]]
I do have so many grails plugins, so i think the manual process will be time consuming. Using configslurper i was able to get the other properties in buildconfig.groovy. but, i am not able to do for the dependency section because it returns [resolution:script13733932805231614944274$runclosure1@71dc48dd]] …
gradle needs a build.gradle under each and every project to specify the dependencies and repositories
Gradle doesn’t need this. If you want, you can configure all projects from a single build script. Actually, you can even omit that, and configure everything from the (mandatory) settings script.
Thanks for the info. I am using some classes from grails in the gradle custom plugin. So, i have added below lines in the build.gradle of the custom plugin
compile "org.grails:grails-bootstrap:2.2.2"
I was able to compile, build, and upload the jar to the nexus repo.
When i try using that plugin in another gradle project , am getting