0

I need some gradle awesomeness.

I have a project with module architecture. It has modules: api, platform and extension modules which are made by using api module. Since I've started to realize this project alone it has a file tree:

root
|
|--api
|
|--platform
|
|--extensions
       |
       |--extension1
       |
       |--extension2
      etc

In each of this components (api, platform, extension1, extension2) file build.gradle exists to compile the module. I want to make a universal build.gradle-script in the root directory to be able to compile all modules of the project in one time and be able to run it and debug (through gradle application-plugin and run task).

I've tried to realize it by adding project dependcies and putting them into dependencies-part of my build.gradle-script in the root directory but it does not work.

I could also make a simple shell script to do that but it is not cool, you know it.

Resume

Need a ONE build.gradle script in the root directory which can compile all the modules in once and after compiling it will gather all files(in my case it is .ini and .jar files) from build/libs directory of each module and copy it into root/build directory.

VP.
  • 15,509
  • 17
  • 91
  • 161
  • Did you create a settings.gradle file next to the root build.gradle to declare all the modules? – Xavier Ducrohet Mar 29 '14 at 18:56
  • Yes. After adding modules into settings.gradle in root `build.gradle` I've tried to use them as dependencies. – VP. Mar 29 '14 at 19:21
  • `settings.gradle` together with project dependencies is the correct solution. It's documented extensively in the "Multi-project builds" chapter of the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html). – Peter Niederwieser Mar 31 '14 at 04:22

1 Answers1

0

What I have is a script that configures itself in two parts. We are an Eclipse development house and I wanted to have a single gradle script that can build whatever Eclipse projects the developers created. The settings file has to include all the sub-projects. Then in the build project is a single build script build.gradle, that configures each sub-project from the Eclipse project and classpath.

The build directories are all peers of each other, with a dummy project for the build script and supporting configuration files (for our products). So we have something like:

/ (root of build tree)
| - build (build project with gradle.build script)
| - proj1
| - proj2
| ...

The settings.gradle script looks like:

include "..:proj1",
        "..:proj2",
        ...

So before we start I have to add all the sub-projects as a dependency of my dummy build project. This means that all the other projects have to build for the build project to build.

beforeEvaluate
{
   subprojects.each
   { p->
      dependencies.compile p
   }
}

Then during the configuration phase I create the proper dependencies, add the source directories, etc.

allprojects
{ proj ->
    // this is most important. This makes the root task depend on the subprojects getting built
    rootTask.dependsOn.add proj.tasks.getByPath("build")

    // some code to read the dependencies
    proj.dependencies.compile project(otherProjectName)

    // some code to read the source directories
    proj.sourceSets.main.resources.srcDir srcDir
}
Zagrev
  • 2,000
  • 11
  • 8
  • Can you explain please ` // some code to read the dependencies proj.dependencies.compile project(otherProjectName)`? – VP. Mar 30 '14 at 08:39
  • You would need to write some code to read the project names of the projects that must be compiled for this project to properly compile. In my case, I read each project's .classpath to extract the projects needed. – Zagrev Mar 30 '14 at 19:30
  • What exactly are you trying to achieve here? All that's required to build everything together is a `settings.gradle` and the correct project dependencies. Then executing `gradle foo` from the root project will execute all tasks named `foo` that exist in the root project or any of its subprojects. – Peter Niederwieser Mar 31 '14 at 04:27