How do I set a common build directory for multi-module builds in the root project directory?


(Sason Ohanian) #1

Hi!

I’m pretty new to gradle and I’m trying to migrate a big ant project to gradle.

I have a hierarchy of projects with a build.gradle file at the root with some common stuff set under subprojects {…

Right now, all project are built into their respective directory, as expected, but I want all projects build directory to be placed under the rootdir.

For example, instead of this:

rootdir rootdir - project1 rootdir - project1 - build rootdir -project2 rootdir -project2 - build

I want this:

rootdir rootdir - build rootdir - build - project1 rootdir - build - project2 rootdir - project1 rootdir - project2

How do I do this?


(Sason Ohanian) #2

Ok, so I found a solution that works, but it seems to be deprecated and soon to be removed.

I added for all subprojects the line: buildDir = new File(rootProject.projectDir, “gradleBuild/” + project.name)

I’m assuming that this isn’t the recommended way of doing it. How am I supposed to do?


(Peter Niederwieser) #3

Please post the exact code you use (not just the ‘buildDir’ line) and the exact deprecation message. Please use HTML code tags for all code.


(Sason Ohanian) #4

It seems I was wrong about the buildDir line causing the deprecated message. I had another line that set transitive = true, which caused the message. I’ll post my code anyways just in case.

apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'se.extenda.core.bootstrap.Bootstrap'
  repositories {
 mavenLocal()
 maven {
  url "http://repository/nexus/content/groups/public"
 }
 mavenCentral()
}
  dependencies {
 runtime subprojects
        ///transitive = true <- this line caused the deprecated message. I don't think it is needed
}
  subprojects {
    sourceCompatibility = 1.6
 targetCompatibility = 1.6
    repositories {
  mavenLocal()
  maven {
   url "http://repository/nexus/content/groups/public"
  }
  mavenCentral()
 }
    test {
  workingDir = rootProject.projectDir
 }
    buildDir = new File(rootProject.projectDir, "gradleBuild/" + project.name)
     dependencies {
  testCompile 'junit:junit:4.11'
  compile 'log4j:log4j:1.2.14'
  compile 'org.mockito:mockito-all:1.9.0'
  compile 'org.powermock:powermock-core:1.4.12'
  compile 'org.powermock:powermock-api-mockito:1.4.12'
  compile 'org.powermock:powermock-api-support:1.4.12'
  compile 'org.powermock:powermock-module-junit4:1.4.12'
  compile 'org.powermock:powermock-reflect:1.4.12'
  compile 'org.powermock:powermock-module-junit4-common:1.4.12'
 }
    sourceSets {
  main {
   java { srcDir 'java/src' }
   resources { srcDir 'java/src' }
  }
  test {
   java { srcDir 'java/testsrc' }
   resources { srcDir 'java/testsrc' }
  }
 }
}