Use Gradle to complete multilevel directory projects - gradle

I'm new to Gradle and I want to ask if Gradle can implement this kind of project structure

Yes it can, and it is called multi-project builds. For information on it, take a look here in the Gradle user guide.
If you are completely new to Gradle, you may want to follow a guide such as this one for creating the basic structure.

Related

Should a gradle root project include a build.gradle file?

When looking at the gradle documentation, the example it gives for multi-project builds states:
Note that the root project does not have a Gradle build file, only a settings file that defines the subprojects to include.
The thing I am wondering is whether or not a root project not having a build file would be considered best practices or if the documentation is vague in that regard.
If you have a need for it, you could yes! For example, I have a few check-environment tasks run at root before running any multi-modules.
If you don't think you need it though, I'm fairly sure you can do without it!
It is commonly used to load project-wide plugins, so one probably should include it.
And it is rather the other way around - one does not need any of the subprojects.

How do I make a custom gradle template?

https://github.com/townsfolk/gradle-templates
After much reading in forums, gradle's jira, and githubs, it seems the above plugin is the popular choice for getting maven archetype-like functionality in Gradle.
It comes with multiple templates to choose from, but how do I make my own?
Is there a guide or something that can kick start me into making my own template?
I have a setup I made to generate a new application with all the boiler plate pieces my company requires. I was able to generate this from an existing project using maven archetypes. I want to accomplish the same in Gradle so I can also take advantage of the ability to run groovy scripts when the generation occurs.
So far it looks like the only way to do this is to fork that project and make my own plugin with added template files and such.
Know this is a old question, but there is a wiki page on how to create your own templates:
https://github.com/townsfolk/gradle-templates/wiki/Template-Customization

Gradle - Single build.gradle with dynamic dependencies

So we have a huge multi-project codebase with structure like below:
C:\Eclipse\Workspace->
AR
DC
CI
..
..
Each project has a build.gradle file which has 80% of the code same with only dependencies section changing for all the projects.
What I want to achieve:
I want to create a parent project named "BuildAllProjects" which would be the ONLY project having build.gradle, settings.gradle and gradle.properties and propose to have a properties file for mentioning the dependencies of each project, something like:
AR=j2ee,commons-lang,FW,DA,Common
DC=commons-codec,FW,DA,Common,spring-core
and then use the gradle expand[] properties to dynamically fill the dependencies for the project which I am building, so for instance, if I am building AR, I may want to run:
gradle -PAR build
which will read dependencies for "AR" from the properties and expand in the form :
dependencies {
compile name 'j2ee'
compile name 'commons-lang'
}
Do you guys think this is possible or is this the WORST way of achieving it? I am new to GRADLE overall and information provided above is based on knowledge that I have acquired in a weeks time. Please provide your suggestions to implement this at the BEST of gradle.
Thanks,
Yogendra
Layering a properties file based build language on top of Gradle's build language doesn't strike me as desirable. Instead, I recommend to focus on writing clean and DRY Gradle build scripts. You can learn more about Gradle's powerful abstraction capabilities (configuration injection, script plugins, buildSrc, custom plugins and extensions, etc.) in the Gradle User Guide.
In a typical multi-project build, subproject build scripts mostly contain dependency declarations, whereas most other configuration happens in the root build script and/or script plugins.

Gradle: Conditional include of subprojects

I have a maven multi-module project (please see the attached image for the structure). I am in the process of migrating to Gradle.
We have multiple profiles inside AppBuild/pom.xml like shown below; and we run our maven build from AppBuild with -P option for the profiles.
Since I am new to Gradle, I am not able to decide what is the best way to go about it. Now, I am thinking to put some conditional include in settings.gradle based on some -P argument, but I am not too sure. Could someone help me how to go about this? What is the best way with some examples.
Thanks in advance.
~ Niranjan
I recently came across the same question, since I have a multiproject build where I want to include a special subproject only on some occasions.
This special subproject only depends on one other subproject and takes approx 1-2min to configure. So I don't want to have it included if I don't want to build it. That saves some build time.
So, what I did was to modify the settings.gradle
if(file('MySpecialProject').exists()){
include ':MySpecialProject'
}
When I do not want to build MySpecialProject I can simply rename/delete its folder. In my case, the folder is a symlink, since this 'subproject' resides in it's own git repo.
Even if #spy writes that if/then/else is not possible in settings, it did work for me.
Conditional include isn't straightforward in Gradle (it's not a first-class feature), and it's unclear why you would need it for so few subprojects. I recommend to start without and add all four subprojects to settings.gradle.

Is Maven a framework that provides mainly an archetype like domain.controller-view in grails?

I´ve been reading lot about, but since there are several web frameworks that uses Maven for the project, I got confused, so I´m not entirely sure if Maven is an archetype that defines an schema to start developing apps by following good practices, or is just some piece of sdk that converts my code to bytecode. Thanks in advance to anyone who can drag me out of my confusion and gave me the required info. BTW is that rigth to say an archetype is a directory structure?
I am not sure if you are reading enough about maven, Maven is a build system which can help you build your application, manage your dependencies, run your tests, create reports and many other things.
First link in google result is http://maven.apache.org/
Apache Maven is a software project management and comprehension tool.
Based on the concept of a project object model (POM), Maven can manage
a project's build, reporting and documentation from a central piece of
information.
Each application has many dependencies and many small tasks that needs to be done before you can run your application, developers define them in a file called POM and that will be a instruction for Maven to build the application. Maven can do pretty much everything other than writing your code. In that sense it is like Genie in the story of Aladdin, you wish for something it will bring it for you.
There is a Grails maven plugin that can populate Grails project with the same convention that Grails uses. It can work with Grails to execute your commands and many other. More importantly it will manage your dependencies.

Resources